A, LOC1
B, LOC3
C, LOC5
我正在尝试将信用卡信息存储到数据库中。我创建了一个protected void Btn_CheckOut_Click(object sender, EventArgs e)
{
int result = 0;
Payment user = new Payment(txt_CardNumber.Text, txt_CardHolderName.Text, txt_ExpirationDate.Text, txt_Cvv.Text);
result = ProductInsert();
/* Session["CardNumber"] = txt_CardNumber.Text;
Session["CardHolderName"] = txt_CardHolderName.Text;
Session["ExpirationDate"] = txt_ExpirationDate.Text;
Session["Cvv"] = txt_Cvv.Text;*/
Response.Redirect("Payment Sucessful.aspx");
}
public int ProductInsert()
{
int result = 0;
string queryStr = "INSERT INTO CustomerDetails(CardNumber, CardHolderName, ExpirationDate, Cvv)"
+ "values (@CardNumber,@CardHolderName, @ExpirationDate, @Cvv)";
try
{
SqlConnection conn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand(queryStr, conn);
cmd.Parameters.AddWithValue("@CardNumber", this.CardNumber);
cmd.Parameters.AddWithValue("@CardHolderName", this.CardHolderName);
cmd.Parameters.AddWithValue("@ExpirationDate", this.ExpirationDate);
cmd.Parameters.AddWithValue("@Cvv", this.Cvv);
conn.Open();
result += cmd.ExecuteNonQuery(); // Returns no. of rows affected. Must be > 0
conn.Close();
return result;
}
catch (Exception ex)
{
return 0;
}
}
}
方法,现在我试图将任何值插入数据库。
此代码给出了错误:
ProductInsert()在当前上下文中不存在