3 개의 텍스트 상자가있는 코드를 작성하려고하는데 상자에 입력 된 정보가 필요하므로 SQL 데이터베이스로 전달해야합니다. 장바구니 기능을하는 그리드 뷰. catch 블록에서 @strItemName의 스칼라 변수를 정의해야한다는 오류가 계속 발생합니다. 여기 내 코드입니다 ... 어떤 도움을 정말로 극명하게 될 것입니다. 죄송 합니다이 코드는 사이트에서 바로 포맷되지 않은 경우이 내 첫 게시물입니다. 미리 감사드립니다.은 SQL INSERT 문에서 scaler 변수를 정의해야합니다.
protected void btnSubmit_Click(object sender, EventArgs e)
{
string strItemName = txtTitle.Text;
string strMovieQuantity = txtNumMovies.Text;
string strMoviePrice = txtPrice.Text;
//string strCurrentUser = HttpContext.Current.User.Identity.Name;
// I need this later to have a current user also inserted into the table
string strConnection = ConfigurationManager.ConnectionStrings["cs3200"].ToString();
SqlConnection myConnection = new SqlConnection(strConnection);
string strSql = "INSERT INTO ShoppingCart ([ItemName], [QuantityOrdered], [UnitPrice]) VALUES (@strItemName, @strQuantityOrdered, @strUnitPrice)";
SqlCommand myCommand = new SqlCommand(strSql, myConnection);
try
{
myConnection.Open();
int intCnt = myCommand.ExecuteNonQuery();
if (intCnt > 1)
{
lblInsert.Text = intCnt.ToString() + "Records was added";
}
else
{
lblInsert.Text = "One Record was inserted";
}
myConnection.Close();
}
catch (Exception ex)
{
lblInsert.Text = "Unable to insert your record" + "</br>";
lblInsert.Text += "Error Message = " + ex.Message;
myConnection.Close();
}
cmd.Parameters.Add() ... 완전히 누락되었습니다. –