我在我的一个管理系统中添加了一个基于服务的数据库(slq2005的),数据库中有一个Attributes表,表中只有三个字段(Att_Color,Att_Style和一个id【自动增长】),
string sql = "insert into Attributes(Att_Color,Att_Style) values('" + color.Text + "','" + yangshi.Text + "')";
sqlhelper.connection();//连接数据苦的方法
SqlCommand cmd = new SqlCommand(sql, sqlhelper.conn);
if ((int)cmd.ExecuteNonQuery() > 0)
{
MessageBox.Show("chenggong");
}
执行完毕后 没有提示任何错误 而且断点调试也没有错误,可是打开数据库后没有插入的数据,更新/删除数据库也是一样。(在SQL server management 中执行insert、update就可以。)
但是如果是查询(select)的话,就可以查出数据。
不知有没有遇到这种情况的,还请高手指教一下,
string sql = "insert into Attributes(Att_Color,Att_Style) values('" + color.Text + "','" + yangshi.Text + "')";
sqlhelper.connection();//连接数据苦的方法
SqlCommand cmd = new SqlCommand(sql, sqlhelper.conn);
if ((int)cmd.ExecuteNonQuery() > 0)
{
MessageBox.Show("chenggong");
}
执行完毕后 没有提示任何错误 而且断点调试也没有错误,可是打开数据库后没有插入的数据,更新/删除数据库也是一样。(在SQL server management 中执行insert、update就可以。)
但是如果是查询(select)的话,就可以查出数据。
不知有没有遇到这种情况的,还请高手指教一下,
int i = (int)cmd.ExecuteNonQuery();
MessageBox.Show(i.ToString());
if (i > 0)
{
MessageBox.Show("chenggong");
}看看i的值是多少?如果是1就表示更新成功了,如果不是的话检查你的sqlhelper.cs类,肯定是你用的那个类有问题!