为什么插入成功数据库也没数据的?求教啊(新手)
namespace 数据录入窗体{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
string numbers = txtNumbers.Text;
string name = txtName.Text;
string address = txtAddress.Text;
string classes = txtClass.Text;
string phone = txtPhone.Text;
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\db_Students.mdf;Integrated Security=True;User Instance=True"))
{
conn.Open();
using(SqlCommand cmd = conn.CreateCommand())
{
= "Insert into tb_students(numbers,name,address,classes,phone) values(@numbers,@name,@address,@classes,@phone)";
//cmd.Parameters.Clear();
cmd.Parameters.Add(new SqlParameter("numbers", numbers));
cmd.Parameters.Add(new SqlParameter("name", name));
cmd.Parameters.Add(new SqlParameter("address", address));
cmd.Parameters.Add(new SqlParameter("classes", classes));
cmd.Parameters.Add(new SqlParameter("phone", phone));
cmd.ExecuteNonQuery();
}
MessageBox.Show("信息导入成功");
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}