c#-SQL删除命令?
当我删除一条记录时,它会工作。但当我关闭程序并再次打开它时,实际上记录并没有被删除c#-SQL删除命令?,c#,sql,ado.net,C#,Sql,Ado.net,当我删除一条记录时,它会工作。但当我关闭程序并再次打开它时,实际上记录并没有被删除 private void button5_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Upper_Stage_Data.mdf;In
private void button5_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\Upper_Stage_Data.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
con.Open();
MessageBox.Show("Delete Current Row of Database Open");
if (MaxRows != 0)
{
SqlCommand Command = new SqlCommand("DELETE FROM Table1 WHERE Data_no='@inc'", con);
try
{
Command.ExecuteNonQuery();
MessageBox.Show("Record Deleted");
}
catch (SqlException)
{
MessageBox.Show("ERROR: Could not delete record");
}
MaxRows--;
if (inc != 0)
{
inc--;
NavigationRecords();
}
else
{
if (MaxRows != 1)
{
inc++;
NavigationRecords();
}
else
{
MessageBox.Show("No Record");
}
}
}
else
{
MessageBox.Show("No Record");
}
con.Close();
MessageBox.Show("Delete Current Row of Database Closed");
con.Dispose();
}
当我搜索时,有些记录无法删除,因为它们是“主”记录。如何才能真正删除该记录?您不需要在“@inc”周围加引号:
SqlCommand Command = new SqlCommand("DELETE FROM Table1 WHERE Data_no=@inc", con);
您还需要提供@inc
参数的值
Command.Parameters.AddWithValue("@inc", inc); //inc is a variable that contain a value for the @inc parameter
虽然直接指定类型并使用
Value
属性比AddWithValue
更好。查看此项了解更多详细信息:您不需要在“@inc”周围加引号:
SqlCommand Command = new SqlCommand("DELETE FROM Table1 WHERE Data_no=@inc", con);
您还需要提供@inc
参数的值
Command.Parameters.AddWithValue("@inc", inc); //inc is a variable that contain a value for the @inc parameter
虽然直接指定类型并使用
Value
属性比AddWithValue
更好。查看此项了解更多详细信息:您不需要在“@inc”周围加引号:
SqlCommand Command = new SqlCommand("DELETE FROM Table1 WHERE Data_no=@inc", con);
您还需要提供@inc
参数的值
Command.Parameters.AddWithValue("@inc", inc); //inc is a variable that contain a value for the @inc parameter
虽然直接指定类型并使用
Value
属性比AddWithValue
更好。查看此项了解更多详细信息:您不需要在“@inc”周围加引号:
SqlCommand Command = new SqlCommand("DELETE FROM Table1 WHERE Data_no=@inc", con);
您还需要提供@inc
参数的值
Command.Parameters.AddWithValue("@inc", inc); //inc is a variable that contain a value for the @inc parameter
虽然直接指定类型并使用
Value
属性比AddWithValue
更好。检查此项了解更多详细信息:是否每次编译时都会将一个新副本(有行)复制到输出目录并供程序使用?是否每次编译时都会将一个新副本(有行)复制到输出目录并供程序使用?是否每次编译时,一个新的副本(有行)被复制到输出目录并被您的程序使用?是否每次编译时,一个新的副本(有行)被复制到输出目录并被您的程序使用?