且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将列添加到现有数据表中?

更新时间:2023-01-31 22:08:50

好,我真的看不到您遇到的问题,因为您似乎完全按照您的要求做了..所以万一您没有意识到它,检查我在您自己的代码中提出的注释,以了解您在何处进行添加
ok I dont really see what you''re having problems with because you seem to have done exactly what you were asking about..so incase you didnt realize it, check up the comments I''ve put up on your own code to know where you did the addition
SqlConnection con;
SqlDataAdapter dladpt;
DataSet dldst;
DataTable mydt;
con = new SqlConnection(ConfigurationSettings.AppSettings["dbstring"]);
dladpt = new SqlDataAdapter("select part_no,part_name from part", con);
dldst = new DataSet();
mydt = new DataTable();
dladpt.Fill(mydt);
DataColumn dcolColumn = new DataColumn("Link", typeof(string));
/* You created a DataColumn here which is the first thing to do when you want to add a column to a DataTable */
mydt.Columns.Add(dcolColumn);
/* You then added the created column to your DataTable, so it should be working */
DataRow drowItem;
foreach (DataRow row in mydt.Columns)
{
drowItem = mydt.NewRow();
drowItem["Link"] = "secret";
mydt.Rows.Add(drowItem);
}
datagridview1.DataSource=mydt;


如果您还有其他意思,则需要更好地加以说明


If you meant something else, then you need to clarify it better