c# 与sql2005数据库的保存问题 。。。。提交不行

来源:百度知道 编辑:UC知道 时间:2024/05/18 07:56:24
private void button8_Click(object sender, EventArgs e)//提交
{
if (textBox5.Text.Trim() == "")//检查非空字段
{
MessageBox.Show("类型名称不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

int n = dataGridView1.CurrentRow.Index;
ds.Tables[0].Rows[n]["类型编号"] = this.textBox5.Text.Trim();
ds.Tables[0].Rows[n]["类型名称"] = this.textBox6.Text.Trim();
ds.Tables[0].Rows[n]["可借天数"] = this.textBox4.Text.Trim();

adapter.Fill(ds,"图书类型");
try
{
SqlCommandBuilder cmdb = new SqlCommandBuilder(adapter);
adapter.Update(ds,"图书类型");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
更新不了数据库,但是没有提示错误
我是用dataGr

你的数据库里的内容该了吗?如果该了的话,并且没有显示的话,好像应该是你的try 里面的代码少了一句吧,当你
adapter.Update(ds,"图书类型"); 以后,你还需要重新绑定一下数据源.
把try
{
SqlCommandBuilder cmdb = new SqlCommandBuilder(adapter);
adapter.Update(ds,"图书类型");
}
里面的换成
try
{ adapter=new SqlDataAdapter("select * from 表名",mycon);
SqlCommandBuilder cmdb = new SqlCommandBuilder(adapter);
adapter.Update(ds,"图书类型");
然后在绑定下;
}

把 catch 里面的改一下,改成 Messagebox.Show(ex.Message) 试试
还有 在前面写入数据的时候
int n = dataGridView1.CurrentRow.Index;
ds.Tables[0].Rows[n]["类型编号"] = this.textBox5.Text.Trim();
ds.Tables[0].Rows[n]["类型名称"] = this.textBox6.Text.Trim();
ds.Tables[0].Rows[n]["可借天数"] = this.textBox4.Text.Trim();
貌似不是这么写的吧???
好像你用的就是使用TEXT文本框显示数据??这样的话麻烦了点,建议使用
DataGridView控件!!很方便的,具体说明网上找吧!

自己调试一下就知道了的
如果sql执行了 数据库要执行一下 才能看到数据的 这种问题要学会自己一解决

什么意思?不能写入数据?