数据库更新错误 [英] database update error
本文介绍了数据库更新错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string tbl = "ConfArticle";
string sqlStr = string.Concat("SELECT * FROM ", tbl);
try
{
OleDbConnection cnn = new OleDbConnection(cnnStr);
OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);
cnn.Open();
OleDbCommand cmd = new OleDbCommand(sqlStr, cnn);
OleDbDataReader drr = cmd.ExecuteReader();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
DataRow dr;
ocb.QuotePrefix = "[";
ocb.QuoteSuffix = "]";
oda.Fill(ds, tbl);
bool found = false;
if (textBox2.Text.Trim() != id4edit.Trim())
while (drr.Read())
{
if (drr["P_ID"].ToString().Trim() == textBox2.Text.Trim())
{
found = true;
break;
}
}
if (!found)
{
dt = ds.Tables[tbl];
for (int i = 0; i < dt.Rows.Count; ++i)
{
dr = dt.Rows[i];
if (dr["P_ID"].ToString().Trim() == id4edit.Trim())
{
dr.BeginEdit();
dr["P_ID"] = textBox2.Text.Trim();
dr["Art_Title"] = textBox6.Text.Trim();
dr["Reg_No"] = textBox4.Text.Trim();
dr.EndEdit();
oda.UpdateCommand = ocb.GetUpdateCommand();
if (oda.Update(ds, tbl) == 1)
{
ds.AcceptChanges();
MessageBox.Show("Updated!!");
}
else
{
ds.RejectChanges();
MessageBox.Show("Rejected");
}
break;
}
}
}
else
MessageBox.Show("Duplicate Error");
drr.Close();
cnn.Close();
dt.Dispose();
ds.Dispose();
drr.Dispose();
cmd.Dispose();
ocb.Dispose();
oda.Dispose();
cnn.Dispose();
dt = null;
ds = null;
drr = null;
cmd = null;
ocb = null;
oda = null;
cnn = null;
}
catch (Exception ex)
{
MessageBox.Show("Error:\n\t" + ex.Message);
}
finally
{
}
我使用此代码来编辑数据库,但是当我按下编辑"按钮时,我看到了
此再次不支持UpdateCommand的动态SQL生成,这是不返回任何键列信息的SelectCommand"错误
请帮助我,我需要它.
i use this code for edit a data base but when i press edit button i see
this "Dynamic SQL generation for the UpdateCommand is not Supported againest a SelectCommand that does not return any key column information" error
please help me i need it
推荐答案
错误消息表明您的SQL表已设置了noch主键.
The error message says that your SQL table has noch primary key set.
这篇关于数据库更新错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文