我在按钮点击事件中出现错误,因为它在此行显示错误消息:
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());
}
答案 0 :(得分:1)
EndExecuteNonQuery
需要提及here in MSDN的IAsyncResult
参数。
另外,这只是一段代码片段吗?因为我认为您会想要使用com.ExecuteNonQuery()
。 EndExecuteNonQuery
是异步执行SQL语句的结束对。