string deleteCmd="delete from tblbooks where BookID like '@bookid'"; cmd=new SqlCommand(deleteCmd,con);
cmd.Parameters.Add(new SqlParameter("@bookid",SqlDbType.Char,10));
cmd.Parameters["@bookid"].Value=this.TxtBookID.Text;
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("删除成功");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
cmd.Connection.Close();
}
this.TxtBookID.Text="";
this.TxtBookName.Text="";
this.TxtBookState.Text="";
}
这是在删除按钮里面执行的,提示删除成功,但是数据库里面还有,为什么啊,怎么修改一下呢?
cmd.Parameters.Add(new SqlParameter("@bookid",SqlDbType.Char,10));
cmd.Parameters["@bookid"].Value=this.TxtBookID.Text;
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("删除成功");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
cmd.Connection.Close();
}
this.TxtBookID.Text="";
this.TxtBookName.Text="";
this.TxtBookState.Text="";
}
这是在删除按钮里面执行的,提示删除成功,但是数据库里面还有,为什么啊,怎么修改一下呢?
把单引号去掉试试
int result = cmd.ExecuteNonQuery();
if(result > 0)
MessageBox.Show("删除成功");
else
MessageBox.Show("删除失败");
cmd = new SqlCommand(deleteCmd,con);
cmd.Parameters.AddWithValue("@bookid", "%" + TxtBookID.Text + "%" );