I'm new in C# programming, so I'll appreciate if anyone can help me. I know there are similar question but I still can't find the solution for my problem. I'm developing a mock system, where when user bought the product, the system will store all the transaction details. the problem is, I cannot insert the data into the database. Here's the code:
using (SqlConnection conn = new SqlConnection
(ConfigurationManager.ConnectionStrings["database"].ConnectionString))
{
string QueryA = "@Insert into TransDetails(AccountNumber,Amount,Provider"
+ ",Mobile Number,TransNum,TransDate, Status) "
+ " Values (@AccountNumber,@Amount,@Provider,@Mobile Number,"
+ "@TransNum,@TransDate,@Status";
using (SqlCommand cmd = new SqlCommand("InsertRecord", conn))
{
conn.Open();
cmd.CommandType = CommandType.Text;
cmd.CommandText = QueryA;
cmd.Parameters.AddWithValue("@AccountNumber", acc.Text);
cmd.Parameters.AddWithValue("@Amount", lblAmount.Text);
cmd.Parameters.AddWithValue("@Provider", lblProvider.Text);
cmd.Parameters.AddWithValue("@Mobile Number", lblNumber.Text);
cmd.Parameters.AddWithValue("@TransNum", lblTrans.Text);
cmd.Parameters.AddWithValue("@TransDate", lblDate.Text);
cmd.Parameters.AddWithValue("@Status", status.Text);
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch
{
lblMessage.Text = "Error";
}
finally
{
conn.Close();
}
}
}
and the stores procedures are as follows:
ALTER PROCEDURE InsertRecord1
@AccountNumber int,
@Amount nchar(10),
@Provider nchar(10),
@MobileNumber int,
@TransNum nchar(10),
@TransDate date,
@Status nchar(10)
AS
Insert into TransDetails(AccountNumber,Amount,Provider,MobileNumber,TransNum,TransDate,Status)
Values (@AccountNumber,@Amount,@Provider,@MobileNumber,@TransNum,@TransDate,@Status)
return
Really appreciate any help. P/S: i dont know why the beginning of the stored procedures started with "alter".