關於更新dataset的問題
DataRow newrow = ds.Tables["user_pass"].NewRow(); ds.Tables["user_pass"].Rows.Add(newrow)
我在datagridview新增了一行,必須把焦點放到其它行之後才可以更新,如果不移動到其它行就不能更新,以下是更新方法 ,到底問題出在哪里
public static int UpdateDataset(string ConnectionSql, DataSet dataset, string tablename)
{
int ii;
string updatesql = "select top 0 * from " + tablename;
SqlConnection conn = new SqlConnection(ConnectionSql);
conn.Open();
SqlTransaction trans = conn.BeginTransaction();
SqlDataAdapter da = new SqlDataAdapter(updatesql, conn);
da.SelectCommand.Transaction = trans;
SqlCommandBuilder cb = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds, tablename);
ds = dataset.Copy();
try
{
ii = da.Update(ds.Tables[0]);
();
}
catch (System.Data.SqlClient.SqlException e)
{
trans.Rollback();
}
return ii;
}