当前位置: 首页>>代码示例>>C#>>正文


C# FileHelperEngine.ReadStringAsDT方法代码示例

本文整理汇总了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("", ",");
		}
开发者ID:BD-GitHub,项目名称:filehelpers,代码行数:55,代码来源:RunTimeClassExtra.cs

示例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);
        }
开发者ID:rohancragg,项目名称:FileHelpers,代码行数:9,代码来源:ClassFromFile.cs

示例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);
            }


        }
开发者ID:BD-GitHub,项目名称:filehelpers,代码行数:41,代码来源:frmDataPreview.cs

示例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);;
 }
开发者ID:rohancragg,项目名称:FileHelpers,代码行数:8,代码来源:frmEasyToDataTable.cs

示例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);
            }
        }
开发者ID:smwhit,项目名称:FileHelpers-fork,代码行数:27,代码来源:frmDataPreview.cs

示例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);
            }
        }
开发者ID:mgmccarthy,项目名称:FileHelpers,代码行数:44,代码来源:frmDataPreview.cs


注:本文中的FileHelperEngine.ReadStringAsDT方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。