主题:紧急求助:数据库事务提交问题?(c#,内含代码)
下面是我写的语句,为什么执行后数据表没有变化?MessageBox.Show(rowsAffected.ToString());显示的数据明明是表的记录数?是不是数据库设置问题?
请高手指点!
using (SqlConnection sqlConnection1 = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\myDate.mdf;Integrated Security=True;User Instance=True"))
{
Int32 rowsAffected;
string queryString = null;
SqlCommand command = new SqlCommand();
sqlConnection1.Open();
command.Connection = sqlConnection1;
command.CommandType = CommandType.Text;
queryString = "delete from City";
command.CommandText = queryString;
rowsAffected = command.ExecuteNonQuery();
sqlConnection1.Close();
MessageBox.Show(rowsAffected.ToString());
}
请高手指点!
using (SqlConnection sqlConnection1 = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\myDate.mdf;Integrated Security=True;User Instance=True"))
{
Int32 rowsAffected;
string queryString = null;
SqlCommand command = new SqlCommand();
sqlConnection1.Open();
command.Connection = sqlConnection1;
command.CommandType = CommandType.Text;
queryString = "delete from City";
command.CommandText = queryString;
rowsAffected = command.ExecuteNonQuery();
sqlConnection1.Close();
MessageBox.Show(rowsAffected.ToString());
}