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


C# System.Data.DataTable.NewRow方法代码示例

本文整理汇总了C#中System.Data.DataTable.NewRow方法的典型用法代码示例。如果您正苦于以下问题:C# System.Data.DataTable.NewRow方法的具体用法?C# System.Data.DataTable.NewRow怎么用?C# System.Data.DataTable.NewRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.DataTable的用法示例。


在下文中一共展示了System.Data.DataTable.NewRow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DataGrid_Initialized

        private void DataGrid_Initialized(object sender, System.EventArgs e)
        {
            // TODO: Delete all this code and replace it with a simple query when database is available.

            SourceDataTable = new System.Data.DataTable("Priorities");
            SourceDataTable.Columns.Add(new System.Data.DataColumn("ID", System.Type.GetType("System.Int32")));
            SourceDataTable.Columns.Add(new System.Data.DataColumn("Name", System.Type.GetType("System.String")));
            SourceDataTable.Columns.Add(new System.Data.DataColumn("Value", System.Type.GetType("System.Int32")));
            SourceDataTable.Columns.Add(new System.Data.DataColumn("Active", System.Type.GetType("System.Boolean")));

            System.Action<int, string, int, bool> AddNewRow = (id, name, value, active) =>
                {
                    var row = SourceDataTable.NewRow();
                    row["ID"] = id;
                    row["Name"] = name;
                    row["Value"] = value;
                    row["Active"] = active;
                    SourceDataTable.Rows.Add(row);
                };

            AddNewRow(1, "Haute", 1, true);
            AddNewRow(2, "Moyenne", 2, true);
            AddNewRow(3, "Faible", 3, true);

            Save();
        }
开发者ID:xeph,项目名称:LOG350.TP3,代码行数:26,代码来源:Priorities.xaml.cs

示例2: DataReaderToDataTable

		public System.Data.DataTable DataReaderToDataTable(MySqlDataReader Reader)
		{
			System.Data.DataTable dt = new System.Data.DataTable();
			System.Data.DataColumn dc;
			System.Data.DataRow dr;
			ArrayList arr = new ArrayList();
			int i;

			for(i=0;i<Reader.FieldCount;i++)
			{
				dc = new System.Data.DataColumn();

				dc.ColumnName = Reader.GetName(i);					
				arr.Add(dc.ColumnName);

				dt.Columns.Add(dc);
			}
			
			while(Reader.Read())
			{
				dr = dt.NewRow();

				for (i=0;i<Reader.FieldCount;i++)
				{
					dr[(string)arr[i]] = Reader[i].ToString();
				}
				dt.Rows.Add(dr);
			}

			Reader.Close();
			return dt;
		}
开发者ID:marioricci,项目名称:erp-luma,代码行数:32,代码来源:DataClass.cs

示例3: ToCSV

        public static void ToCSV(string path, string[,] data)
        {
            System.Data.DataTable dt = new System.Data.DataTable();

            int row = data.GetLength(0);
            int column = data.GetLength(1);
            for (int j = 0; j < column; j++)
            {
                dt.Columns.Add(data[0, j], typeof(String));
            }

            for (int i = 0; i < row; i++)   //含表头
            {
                dt.Rows.Add(dt.NewRow());
                for (int j = 0; j < column; j++)
                {
                    if (!String.IsNullOrEmpty(data[i, j]))
                    {
                        dt.Rows[i][j] = "\"" + data[i, j].Replace("\"", "\"\"") + "\"";
                    }
                }
            }
            dt.AcceptChanges();

            CsvOptions options = new CsvOptions("String[,]", ',', data.GetLength(1));
            CsvEngine.DataTableToCsv(dt, path, options);
        }
开发者ID:niceplayer454,项目名称:cfi,代码行数:27,代码来源:CsvHelper.cs

示例4: GetAllBenchmarks

        private System.Data.DataTable GetAllBenchmarks()
        {
            HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb();
            //HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.Load(@"");
            HtmlAgilityPack.HtmlDocument doc = web.Load(@"http://benchmarksgame.alioth.debian.org/");

            System.Data.DataTable dt = new System.Data.DataTable();

            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Url", typeof(string));

            System.Data.DataRow dr = null;

            foreach (HtmlAgilityPack.HtmlNode link in doc.DocumentNode.SelectNodes("//section[1]//li/a[@href]"))
            {
                dr = dt.NewRow();
                // System.Console.WriteLine(link);
                dr["Name"] = System.Web.HttpUtility.HtmlDecode(link.InnerText);
                dr["Url"] = link.Attributes["href"].Value;

                dt.Rows.Add(dr);
            } // Next link

            System.Data.DataView dv = dt.DefaultView;
            dv.Sort = "Name ASC";
            System.Data.DataTable sortedDT = dv.ToTable();

            return sortedDT;
        }
开发者ID:ststeiger,项目名称:AliothBenchmarkDataExtract,代码行数:29,代码来源:Form1.cs

示例5: Init

        public static void Init()
        {
            dataTable = new System.Data.DataTable("Ivas");
            System.Data.DataColumn myDataColumn;

            myDataColumn = new System.Data.DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.Int32");
            myDataColumn.ColumnName = "Codigo";
            dataTable.Columns.Add(myDataColumn);

            myDataColumn = new System.Data.DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.Int32");
            myDataColumn.ColumnName = "Porcentaje";
            dataTable.Columns.Add(myDataColumn);

            dataTable.PrimaryKey = new System.Data.DataColumn[]{dataTable.Columns["Codigo"]} ;

            System.Data.DataRow dataRow ;
            for ( int i = 0 ; i < 5 ; i++ )
            {
                dataRow = dataTable.NewRow();
                dataRow["Codigo"] = i+1 ;
                dataRow["Porcentaje"] = 0 ;
                dataTable.Rows.Add(dataRow);
            }
        }
开发者ID:riseven,项目名称:TPV,代码行数:26,代码来源:GestorIvas.cs

示例6: CSVToDataTable

 /// <summary>
 /// Export data from CSV file given the full filename.
 /// </summary>
 /// <param name="FileName">CSV file</param>
 /// <returns>DataTable containing data from CSV file. All columns are in string type.</returns>
 public static System.Data.DataTable CSVToDataTable(string FileName)
 {
     #region logic
     System.Data.DataTable result = new System.Data.DataTable();
     System.IO.StreamReader fileReader = null;
     if (!System.IO.File.Exists(FileName))
     {
         throw new System.IO.IOException("File not found!");
     }
     if (new System.IO.FileInfo(FileName).Length == 0)
     {
         throw new Exception("File is EMPTY!");
     }
     try
     {
         fileReader = new System.IO.StreamReader(FileName);
         List<string> headers = RowToList(fileReader.ReadLine());
         foreach (string header in headers)
         {
             System.Data.DataColumn tempColumn = new System.Data.DataColumn();
             tempColumn.ColumnName = header;
             tempColumn.DataType = Type.GetType("System.String");
             result.Columns.Add(tempColumn);
             tempColumn = null;
         }
         string singleRow = "";
         while ((singleRow = fileReader.ReadLine()) != null)
         {
             System.Data.DataRow tempRow = result.NewRow();
             List<string> dataInList = RowToList(singleRow);
             for (int i = 0; i < result.Columns.Count; i++)
             {
                 tempRow.ItemArray[i] = dataInList[i];
             }
         }
     }
     #endregion
     #region exception handling
     catch (Exception AllEx)
     {
         throw AllEx;
     }
     finally
     {
         if (fileReader.BaseStream.CanRead)
         {
             fileReader.Close();
         }
         fileReader = null;
     }
     #endregion
     return result;
 }
开发者ID:yedijas,项目名称:SimpleUtil,代码行数:58,代码来源:CSVutil.cs

示例7: EvaluatorTestArrayDictDataRow

        public void EvaluatorTestArrayDictDataRow()
        {
            var eval = new ExpressionEvaluator();
              //Create an array, a dictionary and a data row and add them to Globals
              eval.Globals["primes"] = new int[] { 3, 5, 7, 11, 13 };
              var nums = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
              nums["one"] = "1";
              nums["two"] = "2";
              nums["three"] = "3";
              eval.Globals["nums"] = nums;
              var t = new System.Data.DataTable();
              t.Columns.Add("Name", typeof(string));
              t.Columns.Add("Age", typeof(int));
              var row = t.NewRow();
              row["Name"] = "John";
              row["Age"] = 30;
              eval.Globals["row"] = row;

              string script;
              object result;

              //Test array
              script = @"primes[3]";
              result = eval.Evaluate(script);
              Assert.AreEqual(11, result, "Unexpected computation result");
              script = @"
            primes[3] = 12345
            primes[3]";
              result = eval.Evaluate(script);
              Assert.AreEqual(12345, result, "Unexpected computation result");

              //Test dict
              script = @"nums['three'] + nums['two'] + nums['one']";
              result = eval.Evaluate(script);
              Assert.AreEqual("321", result, "Unexpected computation result");
              script = @"
            nums['two'] = '22'
            nums['three'] + nums['two'] + nums['one']
            ";
              result = eval.Evaluate(script);
              Assert.AreEqual("3221", result, "Unexpected computation result");

              //Test data row
              script = @"row['Name'] + ', ' + row['age']";
              result = eval.Evaluate(script);
              Assert.AreEqual("John, 30", result, "Unexpected computation result");
              script = @"
            row['Name'] = 'Jon'
            row['Name'] + ', ' + row['age']";
              result = eval.Evaluate(script);
              Assert.AreEqual("Jon, 30", result, "Unexpected computation result");
        }
开发者ID:MarcusTheBold,项目名称:Irony,代码行数:52,代码来源:EvaluatorTests.cs

示例8: TasksListView_Initialized

        private void TasksListView_Initialized(object sender, System.EventArgs e)
        {
            var table = new System.Data.DataTable("Tasks");
            table.Columns.Add(new System.Data.DataColumn("Name"));
            table.Columns.Add(new System.Data.DataColumn("DeadlineID"));
            table.Columns.Add(new System.Data.DataColumn("PriorityID"));
            table.Columns.Add(new System.Data.DataColumn("Completion"));

            var row1 = table.NewRow();
            row1["Name"] = "Rapport du TP3";
            row1["DeadlineID"] = 1;
            row1["PriorityID"] = 1;
            row1["Completion"] = 0.15;
            table.Rows.Add(row1);

            var row2 = table.NewRow();
            row2["Name"] = "Entrevue pour un stage";
            row2["DeadlineID"] = 2;
            row2["PriorityID"] = 2;
            row2["Completion"] = 0;
            table.Rows.Add(row2);

            TasksListView.ItemsSource = table.DefaultView;
        }
开发者ID:xeph,项目名称:LOG350.TP3,代码行数:24,代码来源:MainWindow.xaml.cs

示例9: btnTestAll_Click

        private void btnTestAll_Click(object sender, System.EventArgs e)
        {
            dt = CreateTable();

            string correct = "Brokers México, Intermediario de Aseguro,S.A.";
            string broken = "Brokers México, Intermediario de Aseguro,S.A."; // Get text from database

            correct = this.txtCorrect.Text;
            broken = this.txtWrong.Text;

            System.Text.EncodingInfo[] encs = System.Text.Encoding.GetEncodings();
            for (int i = 0; i < encs.Length; ++i)
            {

                for (int j = 0; j < encs.Length; ++j)
                {
                    System.Data.DataRow dr = dt.NewRow();

                    dr["SourceEncoding"] = encs[i].CodePage;
                    dr["TargetEncoding"] = encs[j].CodePage;

                    System.Text.Encoding enci = System.Text.Encoding.GetEncoding(encs[i].CodePage);
                    System.Text.Encoding encj = System.Text.Encoding.GetEncoding(encs[j].CodePage);

                    byte[] encoded = enci.GetBytes(broken);
                    string corrected = encj.GetString(encoded);

                    dr["Result"] = corrected;

                    dr["SourceEncodingName"] = enci.BodyName;
                    dr["TargetEncodingName"] = encj.BodyName;

                    if (System.StringComparer.InvariantCultureIgnoreCase.Equals(correct, corrected))
                        dt.Rows.Add(dr);
                } // Next j

            } // Next i

            this.dgvResult.DataSource = dt;
        }
开发者ID:ststeiger,项目名称:EncodingGuesser,代码行数:40,代码来源:Form1.cs

示例10: LoadWithFieldMap

        public void LoadWithFieldMap()
        {
            MockRepository mocks = new MockRepository();
            FFLib.Data.DBProviders.IDBProvider dbprovider = mocks.Stub<FFLib.Data.DBProviders.IDBProvider>();
            FFLib.Data.IDBConnection Conn = mocks.Stub<FFLib.Data.IDBConnection>();
            FFLib.Data.DBTable<TestDTO2> dtoTable;
            TestDTO2 expected = new TestDTO2();
            expected.XID = 1;

            System.Data.DataTable dr = new System.Data.DataTable();
            dr.Columns.Add("ID", typeof(int));
            dr.Columns.Add("Name", typeof(String));
            dr.Columns.Add("Status", typeof(string));
            dr.Columns.Add("CreateDate", typeof(DateTime));
            System.Data.DataRow drRow = dr.NewRow();
            drRow["ID"] = 1;
            drRow["Name"] = "test";
            drRow["Status"] = "open";
            drRow["CreateDate"] = DateTime.Now;
            dr.Rows.Add(drRow);

            System.Data.IDataReader idr = dr.CreateDataReader();

            using (mocks.Record())
            {
                dbprovider.Stub(x => x.ExecuteReader(null, null, null)).IgnoreArguments().Repeat.Any().Return(idr);
                Conn.Open();
                LastCall.Repeat.Any();
                Conn.Stub(x => x.InTrx).Repeat.Any().Return(false);
                Conn.Stub(x => x.dbProvider).Return((FFLib.Data.DBProviders.IDBProvider)dbprovider).Repeat.Any();
                Conn.Stub(x => x.State).Repeat.Any().Return(System.Data.ConnectionState.Closed);
            }

            using (mocks.Playback())
            {
                dtoTable = new FFLib.Data.DBTable<TestDTO2>(Conn);
                TestDTO2 result = dtoTable.Load(1);
                Assert.AreEqual(expected.XID, result.XID);
            }
        }
开发者ID:Fast-Forward-llc,项目名称:FFLib,代码行数:40,代码来源:DBTableTests.cs

示例11: ProcessCommand

        public virtual void ProcessCommand(OSAE.OSAEMethod method)
        {
            System.Data.DataTable dt = new System.Data.DataTable();
            System.Data.DataRow row;
            dt.Columns.Add("method_name", typeof(string));
            dt.Columns.Add("object_name", typeof(string));
            dt.Columns.Add("parameter_1", typeof(string));
            dt.Columns.Add("parameter_2", typeof(string));
            dt.Columns.Add("address", typeof(string));
            dt.Columns.Add("object_owner", typeof(string));

            row = dt.NewRow();
            row["method_name"] = method.MethodName;
            row["object_name"] = method.ObjectName;
            row["parameter_1"] = method.Parameter1;
            row["parameter_2"] = method.Parameter2;
            row["address"] = method.Address;
            row["object_owner"] = method.Owner;
            dt.Rows.Add(row);

            _view.ProcessCommand(dt);
        }
开发者ID:nacker90,项目名称:Open-Source-Automation,代码行数:22,代码来源:AdInV1AdapterToV2.cs

示例12: exportTblScripts

        public static void exportTblScripts(DeviceFile.DeviceScripts[] fScripts, String filename)
        {
            DTBL tblScripts= new DTBL("Scripts");
            setupTblScripts( tblScripts);

            System.Data.DataRow myNewRow;

            for (int i = 0; i < fScripts.Length; i++)
            {
                myNewRow = tblScripts.NewRow();

                myNewRow["ScriptNumber"] = fScripts[i].ScriptNumber; //UInt16();
                myNewRow["ScriptName"] = fScripts[i].ScriptName; //String();
                myNewRow["ScriptVersion"] = fScripts[i].ScriptVersion; //UInt16();
                myNewRow["UNUSED1"] = fScripts[i].UNUSED1; //UInt32();
                myNewRow["ScriptLength"] = fScripts[i].ScriptLength; //UInt16();
                myNewRow["Script"] = fScripts[i].Script;  //Unit16[];
                myNewRow["Comment"] = fScripts[i].Comment; //String();

                tblScripts.Rows.Add(myNewRow);
            }

            tblScripts.WriteXml(filename, System.Data.XmlWriteMode.WriteSchema);
        }
开发者ID:timwuu,项目名称:PK2BL32,代码行数:24,代码来源:xmlUtilility.cs

示例13: btnBuscar_Click

        protected void btnBuscar_Click(object sender, EventArgs e)
        {
            Guid rolId = new Guid(ddlBusquedaRoles.SelectedValue);
            System.Data.DataRow row = null;

            List<Usuario> result = Usuario.Buscar(txtBusquedaNombre.Text, txtBusquedaPrimerNombre.Text, txtBusquedaPrimerApellido.Text, rolId);

            System.Data.DataTable tablaUsuarios = new System.Data.DataTable();
            tablaUsuarios.Columns.Add("Id");
            tablaUsuarios.Columns.Add("NombreUsuario");
            foreach (Usuario actual in result)
            {
                row = tablaUsuarios.NewRow();
                row["Id"] = actual.Id.ToString();
                row["NombreUsuario"] = actual.NombreUsuario;
                tablaUsuarios.Rows.Add(row);
            }

            tablaUsuarios.AcceptChanges();

            gvUsuarios.DataSource = tablaUsuarios;

            gvUsuarios.DataBind();
        }
开发者ID:jennchinchi,项目名称:UAM-p4-Inv,代码行数:24,代码来源:Usuarios.aspx.cs

示例14: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            //1.基本設定
            NameValueCollection config = new NameValueCollection();
            config.Add("appId", APP_ID);
            config.Add("secret", APP_SECRET);
            config.Add("redirect_uri", REDIRECT_URI);
            //config.Add("log_path", "d:\\data.log");

            //2.實體化
            FunBuddy f8d = null;
            try
            {
                f8d = new FunBuddy(config);
            }
            catch (ApiException ex)
            {
                Panel1.Visible = false;
                Panel2.Visible = true;
                lblCode.Text = ex.code.ToString();
                lblMessage.Text = ex.message;
                return;
            }

            //3.取得access token (在session裡)
            JObject session = f8d.getSession();
            if (session == null)
            {
                Response.Redirect(f8d.getLoginUrl());
                return;
            }

            //4.取得帳號資料
            try
            {
                JObject me = f8d.api("v1/me/account", "GET", new NameValueCollection());
                lblAccount.Text = me["pid"].ToString();
                lblName.Text = me["username"].ToString();
                Access_Token = f8d.getAccessToken();
                lblAccessToken.Text = Access_Token;
                lblUid.Text = me["uid"].ToString();
            }
            catch (ApiException ex)
            {
                Panel1.Visible = false;
                Panel2.Visible = true;
                lblCode.Text = ex.code.ToString();
                lblMessage.Text = ex.message;
            }

            //5.調用api(ex. 取得好友)
            NameValueCollection param = new NameValueCollection();
            param.Add("start","0");
            param.Add("count","10");
            JObject result = f8d.api("v1/me/friends", "GET", param);
            var q = from p in result.Properties()
                    select p;

            System.Data.DataTable data = new System.Data.DataTable();
            data.Columns.Add("uid");
            data.Columns.Add("username");
            foreach (JProperty friend in q)
            {
                System.Data.DataRow tr = data.NewRow();
                tr["uid"] = result[friend.Name]["uid"].ToString();
                tr["username"] = result[friend.Name]["username"].ToString();
                data.Rows.Add(tr);
            }
            GridView1.DataSource = data;
            GridView1.DataBind();
            //logoutUrl = $fun->getLogoutUrl();
        }
开发者ID:wayi,项目名称:dotnet-sdk,代码行数:72,代码来源:Default.aspx.cs

示例15: DebugPrint

    public override void DebugPrint(string Directory, Dictionary<int, Catchment> Catchments)
    {
      if (ExtraOutput & Update)
      {
        using (ShapeWriter sw = new ShapeWriter(Path.Combine(Directory, Name + "_debug.shp")))
        {
          System.Data.DataTable dt = new System.Data.DataTable();
          dt.Columns.Add("ID15", typeof(int));
          dt.Columns.Add("LakeName", typeof(string));
          dt.Columns.Add("NitrateReduction", typeof(double));
          dt.Columns.Add("NitrateConcentration", typeof(double));
          dt.Columns.Add("FlushingRatio", typeof(double));
          foreach (var c in Catchments.Values.Where(c => c.BigLake != null))
          {
            var row = dt.NewRow();
            row[0] = c.ID;
            row[1] = c.BigLake.Name;
            row[2] = c.BigLake.NitrateReduction.Average;
            row[3] = c.BigLake.NitrateConcentration.Average;
            row[4] = c.BigLake.FlushingRatio.Average;
            sw.Write(new GeoRefData() { Geometry = c.Geometry, Data = row });

            using (StreamWriter st = new StreamWriter(Path.Combine(Directory, Name) +"_" + c.ID + "_debug.csv"))
            {
              st.WriteLine("Time;NitrateReduction;NitrateContration;FlushingRatio");
              for (int i = 0; i < c.BigLake.NitrateReduction.Items.Count; i++)
              {
                st.WriteLine(c.BigLake.NitrateReduction.Items[i].Time.ToString() + ";" + c.BigLake.NitrateReduction.Items[i].Value + ";" + c.BigLake.NitrateConcentration.Items[i].Value + ";" + c.BigLake.FlushingRatio.Items[i].Value);
              }
            }
          }
        }
      }
    }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:34,代码来源:LakeSink.cs


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