I'm trying to make a simple application form were user can input data like 'reservationid', 'bookid', 'EmployeeID' and 'reservedate'. Its from my program Library System. 'reservationid' is an auto increment primary key while the rest are BigInt50, NVarChar50 and DateTime10 respectively. So I'm having this error: Input String was not in a correct format. It worked fine a while ago until I modified the 'reservationid' to auto increment so where did I go wrong? I've attached a sample of my code behind.
Any help would be greatly appreciated! Thanks in advance!
namespace LibraryManagementSystemC4.User { public partial class Reserving : System.Web.UI.Page { public string GetConnectionString() { return System.Configuration.ConfigurationManager.ConnectionStrings["LibrarySystemConnectionString"].ConnectionString; } //string reservationid private void ExecuteInsert(string bookid, string EmployeeID, string reservedate) { SqlConnection conn = new SqlConnection(GetConnectionString()); string sql = "INSERT INTO BookReservation (reservationid, bookid, EmployeeID, reservedate) VALUES " + " (@reservationid, @bookid, @EmployeeID, @reservedate)"; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlParameter[] param = new SqlParameter[3]; //param[0] = new SqlParameter("@reeservationid", SqlDbType.Int, 50); param[0] = new SqlParameter("@bookid", SqlDbType.BigInt, 50); param[1] = new SqlParameter("@EmployeeID", SqlDbType.NVarChar, 50); param[2] = new SqlParameter("@reservedate", SqlDbType.DateTime, 10); //param[0].Value = reservationid; param[0].Value = bookid; param[1].Value = EmployeeID; param[2].Value = reservedate; for (int i = 0; i < param.Length; i++) { cmd.Parameters.Add(param[i]); } cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert error"; msg += ex.Message; throw new Exception(msg); } finally { conn.Close(); } } protected void Page_Load(object sender, EventArgs e) { if (reservationidTextBox != null) { //reservationidTextBox.Text ExecuteInsert(bookidTextBox.Text, EmployeeIDTextBox.Text, reservationidTextBox.Text); ClearControls(Page); } else { Response.Write("Please input ISBN"); bookidTextBox.Focus(); } { //get bookid from Book Details and Employee PIN from current logged-in user bookidTextBox.Text = DetailsView1.SelectedValue.ToString(); EmployeeIDTextBox.Text = HttpContext.Current.User.Identity.ToString(); } } public static void ClearControls(Control Parent) { if (Parent is TextBox) { (Parent as TextBox).Text = string.Empty; } else { foreach (Control c in Parent.Controls) ClearControls(c); } } } }