Click here to Skip to main content
13,146,663 members (67,548 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Guys, Need some expert advise and help. I am a NooB, trying to create a small Windows Form Application that would insert some data into MY SQL Database. On this form, I am using 3 Combo Box, 1 Text Box, 1 Datetime picker and one button for the save action. The Application works fine, the way it is intended to, but the only problem is time does not get updated after every record is inserted to the table. Time remains Constant. Below is the Code, kindly help.

Jagadish K

private void Save_Click(object sender, EventArgs e)
      string sDispatcher = DispatcherName.Text;
      string sDPSNum = DispatchNumber.Text;
      string sDPSType = DPSType.Text;
      DateTime dtDT = dateTimePickerDT.Value;
      string sQueue = QG.Text;
      string query = "INSERT INTO dps_data(DispatcherName, DispatchNumber, DPSType, DateTime, Queue)" +"VALUES( @Dispatcher, @DPSNum, @DPSType, @DT, @Queue)";
      SqlConnection conn = new SqlConnection(connection);
      SqlCommand cmd = new SqlCommand(query, conn);
      cmd.Parameters.Add(new SqlParameter("@Dispatcher", sDispatcher));
      cmd.Parameters.Add(new SqlParameter("@DPSNum", sDPSNum));
      cmd.Parameters.Add(new SqlParameter("@DPSType", sDPSType));
      cmd.Parameters.Add(new SqlParameter("@DT", dtDT));
      cmd.Parameters.Add(new SqlParameter("@Queue", sQueue));
      int result = cmd.ExecuteNonQuery();
      if (result > 0)
         MessageBox.Show("Data Added Successfully");
         MessageBox.Show("Error in Adding Data");
      DispatchNumber.Text = String.Empty;
      DPSType.Text = String.Empty;
      QG.Text = String.Empty;

[Edit - Marcus Kramer Added pre tags and removed irrelevant code]
Posted 31-Jan-13 17:56pm
Updated 31-Jan-13 18:03pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It won't insert because your dtDT variable is not included in your insert statement.
You need to add it to the string query = "INSERT INTO dps_data(DispatcherName, DispatchNumber, DPSType, DateTime, Queue)" +"VALUES( @Dispatcher, @DPSNum, @DPSType, @DT, @Queue)"; statement as another parameter.
JagzKrish 1-Feb-13 0:29am
@Marcus Kramer - Thank you for your assistance, but I really don't understand what you are exactly talking about. Ok, let me make it very simple. When I build the Application, it launches fine and I have all the fields to be filled, I fill in all details and click Save, Data is inserted to the table and as per the button action, connection is closed and all fields are reset, ready for next entry. when the next entry is done, the time remains the same as first entry, no matter how many entries you do, unless you close and relaunch the application. Kindly excuse me, I am no big programmer, hence explaining in layman terms.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170915.1 | Last Updated 1 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100