dataset难题。
obj.New();
//string nFileID = " ";
int nFileID = 0;
string sql = "select * from c_c_products ";
obj.Open();
adp = new SqlDataAdapter(sql,obj.strconn());
adp.MissingSchemaAction = MissingSchemaAction.AddWithKey;
SqlCommandBuilder dbcb = new SqlCommandBuilder(adp);
ds = new DataSet();
adp.Fill(ds, "ds ");
DataTable dbTable = ds.Tables[ "ds "];
DataRow dbRow = dbTable.NewRow();
dbRow[ "f_customerid "] = customerid;
dbTable.Rows.Add(dbRow);
adp.Update(ds, "ds ");
if (!dbRow.IsNull( "id "))
nFileID = Convert.ToInt32(dbRow[ "id "]);
this.Label1.Text = nFileID.ToString();
obj.Close();
这里nFileID只能得到数据表中最大主键ID大一的值。但并不是新增记录的主键ID,如何改这段程序得到,而不是重新读取数据表一次获得。
------解决方案--------------------把 @@IDENTITY 关键字给一个输出参数
------解决方案--------------------建个触发器吧
------解决方案--------------------select @@IDENTITY as newID