逐行添加数据表中的数据

时间:2016-03-15 10:57:08

标签: c# winforms ado.net

我有以下代码我想在Datatable帮助中添加匹配数据。怎么做

    private void GetVehicalIdFromWeb()
    {
        conn = new SqlConnection(Connection1);
        conn.Open();
      //  var LIST=(from a in General.GetQueryable<Ve>)
        string Query = "Select ID,Name from Vehicle ";
        SqlDataAdapter ad = new SqlDataAdapter(Query, conn);
        DataTable dt = new DataTable();
        dtGetVihcale = new DataTable();
        ad.Fill(dt);
        var list = General.GetQueryable<Fleet_VehicleType>(c => c.VehicleType != null);
        foreach (var item in list)
        {          

            var rowsdata = from row in dt.AsEnumerable()
                            where row.Field<string>("Name").Trim() == item.VehicleType
                            select row;

            dtGetVihcale = rowsdata.CopyToDataTable();         

            //dtGetVihcale = rowsdata.CopyToDataTable();

        }

    }
  

请看下面的图片我想一次只有一个记录   数据表如何通过数据表中的循环数据添加

I want insert record different datatable through loop

but in rowsdata its show 36 record but i want only one

0 个答案:

没有答案