当前位置:网站首页>C # problem of updating data: dynamic SQL generation is not supported for multiple base tables

C # problem of updating data: dynamic SQL generation is not supported for multiple base tables

2022-04-23 21:46:00 CSDN Q & A

 public static bool updateData(DataSet ds, DataTable dt, string strsql)    {        bool flag = false;        SqlCommand sqlcmd = new SqlCommand(strsql, ConnectionPool.getPool().getConnection());        using (SqlDataAdapter da = new SqlDataAdapter(sqlcmd))        {            SqlCommandBuilder builder = new SqlCommandBuilder(da);            try            {                da.UpdateCommand = builder.GetUpdateCommand();                int ii = da.Update(ds, dt.TableName);                                 flag = true;            }            catch (SqlException ea)            {                flag = false;                throw new Exception(ea.Message);            }        }        return flag;    }

-- Save button code
private void toolStripButton1_Click(object sender, EventArgs e)
{
gridView2.CloseEditor();
gridView2.UpdateCurrentRow();
updateData(dsBuJian, dtBuJian, "SELECT ID,Des14 FROM TEST1 where 1=2")

updateData(dsBuJian, dtBuJian, "SELECT Matid,OtherDes1 FROM TEST2 where 1=2")

}

Unable to update multiple tables , So I wrote two lists Table update , When executing the above statement , Only the first... Can be executed successfully updateData.
gridView2 The data displayed in the table are two related tables ,SQL as follows ,
SQL=''select a.ID,a.Des14,b.OtherDes1,b.Matid
from TEST1 a with(nolock)
join TEST2 b with(nolock) on a.matid=b.matid"

版权声明
本文为[CSDN Q & A]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204131512511052.html