버튼 클릭 이벤트에 대한 쿼리를 실행하고 싶습니다.다른 함수에서 쿼리 실행
그러나이 쿼리는 다른 함수로 작성됩니다.
여기 내 코드이며 작동하지 않습니다. 내 문제는 무엇입니까?
namespace MCE_Member_Registration
{
public partial class registration_form_view : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("ConnectionString");
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
createform();
}
protected void createform() {
NameValueCollection nvc = Request.Form;
surname.Text = nvc["txt_surname"];
cmd.CommandText = "Insert into mce_applicants_information values(N'" + nvc["txt_surname"] + "')";
}
protected void confirm_Click(object sender, EventArgs e)
{
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
이 쿼리가 비어 실행을 조정합니다. 나는 SqlCommand cmd가 다른 함수에 있다고 생각했기 때문에 ... – user2163530
클래스 수준에서 개체를 설정하기 때문에 나쁜 디자인입니다. –