关于dataAdapter.Update(dt)不成功的问题
dt是一个表 , 里面的内容为数据库中目前的信息
dataTable是和dt相同解构的表,我想用dataTable中的内容替换掉dt中的内容,
然后更新回数据库,可是就是不成功!
int resultCount = 0;
DataTable dt = new DataTable();
using (SqlConnection sqlconnection = new SqlConnection(connString))
{
if (sqlconnection.State != ConnectionState.Open)
sqlconnection.Open();
SqlTransaction sqltransaction = sqlconnection.BeginTransaction();
SqlCommand cmd = new SqlCommand(selectText, sqlconnection, sqltransaction);
PrepareCommand(cmd, CommandType.Text, cmdParms);
SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
try
{
dataAdapter.Fill(dt);
dt.Clear();
foreach (DataRow dr in dataTable.Rows)
{
dt.ImportRow(dr);
}
dt.GetChanges();