Submit Button (to SQL Server DB) Not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mcupito
    Contributor
    • Aug 2013
    • 294

    Submit Button (to SQL Server DB) Not working

    I have a submit button, where users are clicking after entering text into textboxes and (hopefully) check boxes (for yes/no).

    Here is my code, and when I run it and press submit, there is no action. It just continues to loop. Any ideas why?

    Code:
     string ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True";
    
                using (SqlConnection dataConnection = new SqlConnection(ConnectionString))
                {
                    using (SqlCommand dataCommand = dataConnection.CreateCommand())
                    {
                        dataCommand.CommandText = "INSERT INTO Review_Tbl (course_num, courseName, courseDesc, numQuiz, courseRating, txtBook, txtGrade) " + "VALUES(@CourseNumtxt, @CourseNametxt, @CourseDesctxt, @Quiztxt, @Ratingtxt, @txtBook, @txtGrade)";
    
                        dataCommand.Parameters.AddWithValue("@CourseNumtxt", CourseNumtxt.Text);
                        dataCommand.Parameters.AddWithValue("@CourseNametxt", CourseNametxt.Text);
                        dataCommand.Parameters.AddWithValue("@CourseDesctxt", CourseDesctxt.Text);
                        //dataCommand.Parameters.AddWithValue("@MandatoryCbx", MandatoryCbx.Checked);
                        //dataCommand.Parameters.AddWithValue("@AttendanceCbx", AttendanceCbx.Checked);
                        dataCommand.Parameters.AddWithValue("@Quiztxt", Quiztxt.Text);
                        //dataCommand.Parameters.AddWithValue("@RepeatCbx", RepeatCbx.Checked);
                        dataCommand.Parameters.AddWithValue("@Ratingtxt", Ratingtxt.Text);
                        dataCommand.Parameters.AddWithValue("@txtBook", txtBook.Text);
                        dataCommand.Parameters.AddWithValue("@txtGrade", txtGrade.Text);
    
                        dataConnection.Open();
                        dataCommand.ExecuteNonQuery();
                        dataConnection.Close();
    Note: I took out the Checkboxes in the code to hopefully get a successful run, to no avail.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    I don't see a loop?
    Are you sure there is a continuous loop?
    Or perhaps your connection string is incorrect and you haven't waited long enough for the database to time out?

    -Frinny

    Comment

    • mcupito
      Contributor
      • Aug 2013
      • 294

      #3
      I found the error. It was actually mismatches in naming between my sql statement and my database.

      The loop I was referring to was actually "Waiting for localhost".. aka what I was entering was never truly being submitted.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        I'm glad you solved it :)

        Comment

        Working...