EndExecuteNonQuery错误

时间:2014-03-21 01:10:43

标签: c# asp.net sql

我在按钮点击事件中出现错误,因为它在此行显示错误消息:

com.EndExecuteNonQuery();

消息文本:错误2方法' EndExecuteNonQuery'没有重载取0个参数

感谢您的支持

  protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["usradmadslistview"].ConnectionString);
        conn.Open();

        string cmdStr = "Select count(*) from UserInfo where UID = '" + UsrNme.Text + "'";
        SqlCommand com = new SqlCommand(cmdStr, conn);
        int temp = Convert.ToInt32(com.ExecuteScalar().ToString());


        if (temp == 1)
        {
            chkusrnamlbl.Visible = true;
        }

        conn.Close();
    }
}





protected void btnSave_Click(object sender, EventArgs e)
{
    try
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["usradmadslistview"].ConnectionString);
        conn.Open();

        string insertquery = "insert into UserInfo (UID,FN,LN,Password,Email,CountID,State,City) Values (@username,@firstn,@lastn,@passbox,@email1,@country,@state,@city)";
        SqlCommand com = new SqlCommand(insertquery, conn);
        com.Parameters.AddWithValue("@username", UsrNme.Text);
        com.Parameters.AddWithValue("@firstn", fnbox.Text);
        com.Parameters.AddWithValue("@lastn", lnamebox.Text);
        com.Parameters.AddWithValue("@passbox", passtxtbx1.Text);
        com.Parameters.AddWithValue("@email1", emailbox.Text);
        com.Parameters.AddWithValue("@country", DrDncoundrlst.SelectedItem.ToString());
        com.Parameters.AddWithValue("@state", DropDownListSwestate.SelectedItem.ToString());
        com.Parameters.AddWithValue("@city", citytxtbox.Text);

        com.EndExecuteNonQuery();
        Response.Redirect("User panel.aspx");

        conn.Close();
    }

   catch(Exception ex) {
        Response.Write("Error:" + ex.ToString());
    }

1 个答案:

答案 0 :(得分:1)

EndExecuteNonQuery需要提及here in MSDNIAsyncResult参数。

另外,这只是一段代码片段吗?因为我认为您会想要使用com.ExecuteNonQuery()EndExecuteNonQuery是异步执行SQL语句的结束对。