Update 无法找到 TableMapping['TB_ADMIN'] 或 DataTable“TB_ADMIN”。
以下是代码:namespace 人力资源管理系统
{
public partial class Control_Admin : Form
{
public Control_Admin()
{
InitializeComponent();
}
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
SqlCommandBuilder cb = new SqlCommandBuilder();
SqlCommand cmd = new SqlCommand();
private string str = "Server= localhost;DataBase=Hr_Bs;Uid=sa;Pwd=60202811";
private void btnShow_Click(object sender, EventArgs e)
{
try
{
string aId = txtAid.Text;
string sql = "select * from TB_ADMIN where 管理员编号 = '" + aId + "'";
SqlConnection conn = new SqlConnection(str);
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = sql;
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "TB_ADMIN");
dataGridView1.DataSource = ds.Tables[0];
}
catch
{
MessageBox.Show("您输入的管理员不存在或错误,请重新输入!");
}
}
private void btnChange_Click(object sender, EventArgs e)
{
string aId = txtAid.Text;
string sql = "select * from TB_ADMIN where 管理员编号 = '" + aId + "'";
SqlConnection conn = new SqlConnection(str);
cmd = conn.CreateCommand();
cmd.CommandText = sql;
SqlDataAdapter da = new SqlDataAdapter(cmd);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.SelectCommand = cb.GetInsertCommand();
da.UpdateCommand = cb.GetUpdateCommand();
da.DeleteCommand = cb.GetDeleteCommand();
da.Update(ds,"TB_ADMIN");
dataGridView1.Update();
MessageBox.Show("更新数据成功!");
}
}
}
如题,可以正常的实现查询功能,但是没法更新数据,总是显示:“Update 无法找到 TableMapping['TB_ADMIN'] 或 DataTable“TB_ADMIN”。”想求高手们帮我解决下这个问题,新手,请解释的详细一点,谢谢~~ --------------------编程问答-------------------- da.Update(ds,"TB_ADMIN");
改为
da.Update(ds);
试试
--------------------编程问答-------------------- 最刚开始就是da.Update(ds);后来不行才改的那个
补充:.NET技术 , C#