我可以读取数据库中的一行和一列,但是当我想写入同一个地方时,我收到一条错误消息,我不明白可能出了什么问题?
我收到此错误消息:
对于不返回任何键列信息的 SelectCommand,不支持为 UpdateCommand 生成动态 sql
我的代码:
public void LoadData()
{
connection = new SqlConnection(connectionString);
dataset = new DataSet();
sql = "SELECT * From Guests";
try
{
connection.Open();
adapter = new SqlDataAdapter(sql, connection);
adapter.Fill(dataset, "Guests");
connection.Close();
string test = Convert.ToString(dataset.Tables["Guests"].Rows[0][1]);
MessageBox.Show(test, "This is only a test!",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
dataset.Tables["Guests"].Rows[0][1] = "Hello";
connection.Open();
new SqlCommandBuilder(adapter);
adapter.Update(dataset.Tables["Guests"]);
connection.Close();
}
catch
{
throw;
}
}