简体   繁体   中英

insert a column and data in to dataset

I went through many examples online and spent more time on it, but didn't work for me. i might be doing something wrong.

for existing dataset am trying to add columns by

 ds.Tables[0].Columns.Add("columnName", typeof(string));

any suggestions how to add data to the added column.

Try this for a moment:

ds.Tables[0].Columns.Add(new DataColumn("columnName",typeof(string)));

Found here: adding-rows-to-dataset

I figured this way

foreach (DataRow row in ds.Tables[0].Rows)
    {
      foreach (DataColumn col in ds.Tables[0].Columns)
      {
         string colName = col.ToString();
         if (colName.Contains("columnAmlooking"))
           row[columnAmlooking] = "inputvalue";
       }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM