Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET3.5 C#
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.
 
Regards
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);
      conn.Open();
 
      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");
      }
      else
      {
         MessageBox.Show("Error in Adding Data");
      }          
 
      conn.Close();
 
      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 18:56pm
Edited 31-Jan-13 19:03pm
v2

1 solution

Rate this: bad
good
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.
  Permalink  
Comments
JagzKrish at 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
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 Afzaal Ahmad Zeeshan 170
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 1 Feb 2013
Copyright © CodeProject, 1999-2014
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