执行以下代码时:
private void button1_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(global::DataBase.Properties.Settings.Default.Database1ConnectionString);
try
{
string sql = "INSERT INTO student (stdid,stdname) values("+tid.Text+",N'"+tname.Text+"')";
SqlCommand exeSql=new SqlCommand(sql,cn);
cn.Open();
exeSql.EndExecuteNonQuery(); // <-- Error occurs here
MessageBox.Show("Add new Record Done||","Message",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.studentTableAdapter.Fill(this.database1DataSet.student);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
cn.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.studentTableAdapter.Fill(this.database1DataSet.student);
}
}}
我得到了“没有方法重载'EndExecuteNonQuery'接受0参数”错误。
如何解决此错误?
答案 0 :(得分:2)
请尝试使用ExecuteNonQuery()
。