Fadugba Jeremiah

Fadugba Jeremiah

  • NA
  • 49
  • 18.2k

Error in saving from windows form to database

Nov 5 2013 5:42 AM
please i'm having error in saving from my windows form using textboxes to my database(sql management studio). when debuging, i have this error at the highlighted line in blue here's the code. thanks
 private void button1_Click(object sender, EventArgs e) 
  {
  try
  {
  string connectionString = @"Data Source=JEREMIAH-HP\SQLEXPRESS;Initial Catalog=CourseInfo;Integrated Security=True";
  SqlConnection sqlCon = new SqlConnection(connectionString);
  sqlCon.Open();

  using (SqlConnection connection = new SqlConnection(connectionString))
  using (SqlCommand command = connection.CreateCommand())
  {
  command.CommandText = "INSERT INTO STUDINFO_TBL(MATRICNO,FIRST_NAME, LAST_NAME, DEPT,LEVEL,CGPA,MODEOFENTRY) VALUES (@MATRICNO, @ FIRST_NAME, @LAST_NAME, @DEPT, @LEVEL, @CGPA, @MODEOFENTRY)";

  command.Parameters.AddWithValue("@ MATRICNO",matno);
  command.Parameters.AddWithValue("@FIRST_NAME",frstname);
  command.Parameters.AddWithValue("@LAST_NAME", lastname);
  command.Parameters.AddWithValue("@DEPT",department );
  command.Parameters.AddWithValue("@LEVEL",level );
  command.Parameters.AddWithValue("@CGPA",mycgpa);
  command.Parameters.AddWithValue("@MODEOFENTRY",modeofentry);

  connection.Open();
  command.ExecuteNonQuery();
  }
  sqlCon.Close();
  }
  catch (SqlException ex)
  {
  MessageBox.Show("There is an Error in saving file" + ex);
  }
  }
please assist me

Answers (1)