错误"方法没有超载' EndExecuteNonQuery'取0个参数"

时间:2015-04-03 08:45:07

标签: c# visual-studio-2012

执行以下代码时:

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参数”错误。

如何解决此错误?

1 个答案:

答案 0 :(得分:2)

请尝试使用ExecuteNonQuery()