本文整理汇总了C#中FileHelperEngine.ReadStringAsDT方法的典型用法代码示例。如果您正苦于以下问题:C# FileHelperEngine.ReadStringAsDT方法的具体用法?C# FileHelperEngine.ReadStringAsDT怎么用?C# FileHelperEngine.ReadStringAsDT使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHelperEngine
的用法示例。
在下文中一共展示了FileHelperEngine.ReadStringAsDT方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadAsDataTable1
public void ReadAsDataTable1()
{
DelimitedClassBuilder cb = new DelimitedClassBuilder("ImportContact", ",");
cb.IgnoreEmptyLines = true;
cb.GenerateProperties = true;
cb.AddField("FirstName", typeof(string));
cb.LastField.TrimMode = FileHelpers.TrimMode.Both;
cb.LastField.FieldQuoted = false;
cb.AddField("LastName", typeof(string));
cb.LastField.TrimMode = TrimMode.Both;
cb.LastField.FieldQuoted = false;
cb.AddField("StreetNumber", typeof(string));
cb.LastField.TrimMode = TrimMode.Both;
cb.LastField.FieldQuoted = false;
cb.AddField("StreetAddress", typeof(string));
cb.LastField.TrimMode = TrimMode.Both;
cb.LastField.FieldQuoted = false;
cb.AddField("Unit", typeof(string));
cb.LastField.TrimMode = TrimMode.Both;
cb.LastField.FieldQuoted = false;
cb.AddField("City", typeof(string));
cb.LastField.TrimMode = TrimMode.Both;
cb.LastField.FieldQuoted = false;
cb.AddField("State", typeof(string));
cb.LastField.TrimMode = TrimMode.Both;
cb.LastField.FieldQuoted = false;
cb.AddField("Zip", typeof(string));
cb.LastField.TrimMode = TrimMode.Both;
cb.LastField.FieldQuoted = false;
engine = new FileHelperEngine(cb.CreateRecordClass());
string source = "Alex & Jen,Bouquet,1815,Bell Rd,, Batavia,OH,45103" + Environment.NewLine +
"Mark & Lisa K ,Arlinghaus,1817,Bell Rd,, Batavia,OH,45103" + Environment.NewLine +
"Ed & Karen S ,Craycraft,1819,Bell Rd,, Batavia,OH,45103" + Environment.NewLine;
DataTable contactData = engine.ReadStringAsDT(source);
Assert.AreEqual(3, contactData.Rows.Count);
Assert.AreEqual(8, contactData.Columns.Count);
Assert.AreEqual("Alex & Jen", contactData.Rows[0][0].ToString());
Assert.AreEqual("Mark & Lisa K", contactData.Rows[1][0].ToString());
// new DelimitedClassBuilder("", ",");
}
示例2: ReadFile
public void ReadFile()
{
Type t = ClassBuilder.ClassFromSourceFile(TestCommon.GetPath("Classes", "ClassFromFile.cs"));
var engine = new FileHelperEngine(t);
DataTable dt = engine.ReadStringAsDT("");
Assert.AreEqual(0, dt.Rows.Count);
}
示例3: cmdReadTest_Click
private void cmdReadTest_Click(object sender, EventArgs e)
{
try
{
string classStr = sdClassOut.Text;
Type mType = null;
switch (cboClassLeng.SelectedIndex)
{
case 0:
mType = ClassBuilder.ClassFromString(classStr, NetLanguage.CSharp);
break;
case 1:
mType = ClassBuilder.ClassFromString(classStr, NetLanguage.VbNet);
break;
default:
break;
}
try
{
FileHelperEngine engine = new FileHelperEngine(mType);
DataTable dt = engine.ReadStringAsDT(txtInput.Text);
dgPreview.DataSource = dt;
lblResults.Text = dt.Rows.Count.ToString() + " Rows - " + dt.Columns.Count.ToString() + " Fields";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error Parsing the Sample Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error Compiling Class", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
示例4: cmdRun_Click
/// <summary>
/// Read the file as a data table
/// </summary>
private void cmdRun_Click(object sender, EventArgs e)
{
FileHelperEngine engine = new FileHelperEngine(typeof (CustomersFixed));
DataGridDatos.DataSource = engine.ReadStringAsDT(txtData.Text);;
}
示例5: RunTest
private void RunTest()
{
try
{
string classStr = mLastCode;
var selected = cboClassLanguage.SelectedItem as NetLanguageList.LanguageType;
Type mType = ClassBuilder.ClassFromString(classStr, selected.Language);
try
{
FileHelperEngine engine = new FileHelperEngine(mType);
DataTable dt = engine.ReadStringAsDT(txtInput.Text);
dgPreview.DataSource = dt;
lblResults.Text = dt.Rows.Count.ToString() + " Rows - " + dt.Columns.Count.ToString() + " Fields";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error Parsing the Sample Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error Compiling Class", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
示例6: RunTest
private void RunTest()
{
try {
string classStr = mLastCode;
var selected = cboClassLanguage.SelectedItem is NetLanguage
? (NetLanguage) cboClassLanguage.SelectedItem
: NetLanguage.CSharp;
var type = ClassBuilder.ClassFromString(classStr, selected);
FileHelperEngine engine = new FileHelperEngine (type);
engine.ErrorMode = ErrorMode.SaveAndContinue;
DataTable dt = engine.ReadStringAsDT (txtInput.Text);
if (engine.ErrorManager.Errors.Length > 0)
{
dt = new DataTable ();
dt.Columns.Add ("LineNumber");
dt.Columns.Add ("ExceptionInfo");
dt.Columns.Add ("RecordString");
foreach (var e in engine.ErrorManager.Errors)
{
dt.Rows.Add (e.LineNumber, e.ExceptionInfo.Message, e.RecordString);
}
dgPreview.DataSource = dt;
MessageBox.Show ("Error Parsing the Sample Data",
"Layout errors detected",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else
{
dgPreview.DataSource = dt;
lblResults.Text = dt.Rows.Count.ToString () + " Rows - " + dt.Columns.Count.ToString () + " Fields";
}
}
catch (Exception ex) {
MessageBox.Show(ex.Message, "Error Compiling Class", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}