如果我取DATASET时使用了类似select table1.name,table2.*
from table1,table2
where table1.code= table2.code这样的语句构成的新表
那么在DASTSET中数据变动后,有没有办法一次UPDATE回到DB的原表table2 中?
from table1,table2
where table1.code= table2.code这样的语句构成的新表
那么在DASTSET中数据变动后,有没有办法一次UPDATE回到DB的原表table2 中?
http://topic.csdn.net/t/20030324/10/1568215.html
的回复,考虑了自己生成InsertCommand命令来完成Update,但无法把数据插入数据库,代码如下:
OdbcConnection Myconnection = new OdbcConnection(MyConString);
Myconnection.Open();
DataSet ds = new DataSet();
string tablename = "CSDN";
string sql = "select table1.username,table2.Name,table3.*
from table1,table2,table3
where table1.usercode = table3.usercode
and table2.vediocode = table3.vediocode";
OdbcDataAdapter da = new OdbcDataAdapter(sql, Myconnection);
da.Fill(ds, tablename); //建立DS并FILL数据//添加新的一个DATAROW进入DATASET.TABLE["CSDN"];OdbcCommand ada = new OdbcCommand("Insert into table3(usercode,vediocode,control,rec,play) values(@usercode,@vediocode,@control,@rec,@play)",Myconnection);
ada.Parameters.Add("@usercode", OdbcType.Int);
ada.Parameters.Add("@vediocode", OdbcType.Int);
ada.Parameters.Add("@control", OdbcType.VarChar);
ada.Parameters.Add("@rec", OdbcType.VarChar);
ada.Parameters.Add("@play", OdbcType.VarChar);
ada.Parameters["@usercode"].SourceColumn = "usercode";
ada.Parameters["@vediocode"].SourceColumn = "vediocode";
ada.Parameters["@control"].SourceColumn = "control";
ada.Parameters["@rec"].SourceColumn = "rec";
ada.Parameters["@play"].SourceColumn = "play"; da.InsertCommand = ada;
int errNum = da.Update(ds,tablename);
Myconnection.Close();一直在运行到 int errNum = da.Update(ds,tablename); 发生异常
不知道是什么原因
不知道是什么原因提示什么错误
OdbcCommand ada = new OdbcCommand("Insert into Authority(vediocode,usercode,control,rec,play) values(@vediocode,@usercode,@control,@rec,@play)", Myconnection);也就是把字段 vediocode和usercode的位置换了一下,结果提示错误就变成了
ERROR [HY000] [MySQL][ODBC 3.51 Driver][mysqld-4.0.15-nt]Column 'vediocode' cannot be null这是不是说不是数据集里具体的数据列中有空值,而是语句在取第一个参数"@vediocode"时就没有取到?所以变成空值了