我真的不知道为什么我会收到这条消息
ExecuteNonQuery:CommandText 属性尚未初始化
我的代码完全没有错误,当我查看它时它看起来不错。我一直在网上寻找解决方案,但找不到任何解决方案。这是我的代码。非常感谢任何帮助。
SqlConnection conn = new SqlConnection("Data Source=VALONS;Initial Catalog=gym;Integrated Security=True");
SqlCommand cmd;
public NewMem()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void NewMem_Load(object sender, EventArgs e)
{
}
private void btnSave_Click(object sender, EventArgs e)
{
try
{
conn.Open();
cmd = new SqlCommand("Insert into member(SocialSecurity, Name, City, Street, Zipcode, Email, Phone) values ('" + textSocialSecurity + "','" + textName + "','" + textCity + "','" + textStreet + "','" + textZipCode + "','" + textEmail + "','" + textPhone + "')" + conn);
cmd.ExecuteNonQuery();
MessageBox.Show("You have successfully inserted values in Member");
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}