Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Datepicker value not saved in MySql database

C# Datepicker value not saved in MySql database

Scheduled Pinned Locked Moved C#
csharpdatabasemysqlwinformshelp
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ahmed_one
    wrote on last edited by
    #1

    Hi to All, I am using C# Winforms to create a Voucher system which is Master/Detail, using MySql as backend. Create Voucher class to setup followings: 1.Create New Voucher 2. Save Voucher 3. Query Voucher Currently having problem with Save Voucher, I've setup Insert/Update/Delete commands, to make this post short I am posting Insert commands so that general idea of application will be clear: Class Variables

    ClsMgt da = new ClsMgt();
    MySqlDataAdapter sqlDataMaster = new MySqlDataAdapter();
    private DataSet oDs = null;
    MySqlCommand selectcommand = null;
    MySqlCommand insertcommand = null;
    MySqlCommand updatecommand = null;
    MySqlCommand deletecommand = null;
    private DataTable dt = null;
    private DataTable dtDet = null;
    private String sSelProcName = null;
    private String sInsProcName = null;
    private String sDelProcName = null;
    private String sUpdProcName = null;
    private int voucType;

    public MySqlConnection oCn = new MySqlConnection();
    MySqlTransaction oTrn = null;

    Following is the NewVoucher procedure which will setup VoucherForm to open with blank record:

    public DataSet NewVoucher()
    {
    DataSet vDs = new DataSet();
    oCn = da.GetConnection();

     if (oCn == null)
       {
           oCn.Open();
       }
       try
       {
        DataTable dt = new DataTable();
            //===============================================================================
        //--- Set up the Select Command
            //===============================================================================
    

    String sqlSelect = "Select vID, vTypeID, vNo, accCodeDR, accCodeCR, vDate, vChqNo, vChqDt, vPayName, vRemarks, vAmount from vMaster";
    sqlDataMaster = new MySqlDataAdapter(sqlSelect, oCn);
    sqlDataMaster.FillSchema(dt, SchemaType.Source);
    vDs.Tables.Add(dt);
    VoucherDetails vdet = new VoucherDetails();
    DataTable dtDet = new DataTable();
    dtDet = vdet.NewVoucherDet();

    vDs.Tables.Add(dtDet);

    vDs.Tables[0].Columns["vID"].AutoIncrement = true;
    vDs.Tables[0].Columns["vID"].AutoIncrementSeed = -1;
    vDs.Tables[0].Columns["vID"].AutoIncrementStep = -1;
    vDs.Tables[1].Columns["vID"].AutoIncrement = true;
    vDs.Tables[1].Columns["vID"].AutoIncrementSeed = -1;
    vDs.Tables[1].Columns["vID"].AutoIncrementStep = -1;
    vDs.EnforceConstraints = false;
    vDs.Relations.Add("VouchersToVoucherDetails", vDs.Tables[0].Columns["vID"], vDs.Tables[1].Columns["vID"]);

        }
        catch (MySqlException e)
        {
    
    L 1 Reply Last reply
    0
    • A ahmed_one

      Hi to All, I am using C# Winforms to create a Voucher system which is Master/Detail, using MySql as backend. Create Voucher class to setup followings: 1.Create New Voucher 2. Save Voucher 3. Query Voucher Currently having problem with Save Voucher, I've setup Insert/Update/Delete commands, to make this post short I am posting Insert commands so that general idea of application will be clear: Class Variables

      ClsMgt da = new ClsMgt();
      MySqlDataAdapter sqlDataMaster = new MySqlDataAdapter();
      private DataSet oDs = null;
      MySqlCommand selectcommand = null;
      MySqlCommand insertcommand = null;
      MySqlCommand updatecommand = null;
      MySqlCommand deletecommand = null;
      private DataTable dt = null;
      private DataTable dtDet = null;
      private String sSelProcName = null;
      private String sInsProcName = null;
      private String sDelProcName = null;
      private String sUpdProcName = null;
      private int voucType;

      public MySqlConnection oCn = new MySqlConnection();
      MySqlTransaction oTrn = null;

      Following is the NewVoucher procedure which will setup VoucherForm to open with blank record:

      public DataSet NewVoucher()
      {
      DataSet vDs = new DataSet();
      oCn = da.GetConnection();

       if (oCn == null)
         {
             oCn.Open();
         }
         try
         {
          DataTable dt = new DataTable();
              //===============================================================================
          //--- Set up the Select Command
              //===============================================================================
      

      String sqlSelect = "Select vID, vTypeID, vNo, accCodeDR, accCodeCR, vDate, vChqNo, vChqDt, vPayName, vRemarks, vAmount from vMaster";
      sqlDataMaster = new MySqlDataAdapter(sqlSelect, oCn);
      sqlDataMaster.FillSchema(dt, SchemaType.Source);
      vDs.Tables.Add(dt);
      VoucherDetails vdet = new VoucherDetails();
      DataTable dtDet = new DataTable();
      dtDet = vdet.NewVoucherDet();

      vDs.Tables.Add(dtDet);

      vDs.Tables[0].Columns["vID"].AutoIncrement = true;
      vDs.Tables[0].Columns["vID"].AutoIncrementSeed = -1;
      vDs.Tables[0].Columns["vID"].AutoIncrementStep = -1;
      vDs.Tables[1].Columns["vID"].AutoIncrement = true;
      vDs.Tables[1].Columns["vID"].AutoIncrementSeed = -1;
      vDs.Tables[1].Columns["vID"].AutoIncrementStep = -1;
      vDs.EnforceConstraints = false;
      vDs.Relations.Add("VouchersToVoucherDetails", vDs.Tables[0].Columns["vID"], vDs.Tables[1].Columns["vID"]);

          }
          catch (MySqlException e)
          {
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Try this:

      txtChqDt.DataBindings.Add(new Binding("Value", bs, "vChqDt"));

      (Bind to the "Value" property instead of the "Text" property of txtChqDt).

      A 1 Reply Last reply
      0
      • L Lost User

        Try this:

        txtChqDt.DataBindings.Add(new Binding("Value", bs, "vChqDt"));

        (Bind to the "Value" property instead of the "Text" property of txtChqDt).

        A Offline
        A Offline
        ahmed_one
        wrote on last edited by
        #3

        Thanks for your reply, I will definitely try this.. Meanwhile I've noticed that when form load, and if user manually select date in datetimepicker, ONLY then date is saved!!!! Otherwise not.... Any thoughts???

        L 1 Reply Last reply
        0
        • A ahmed_one

          Thanks for your reply, I will definitely try this.. Meanwhile I've noticed that when form load, and if user manually select date in datetimepicker, ONLY then date is saved!!!! Otherwise not.... Any thoughts???

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I'm not clear on what / when "Otherwise not" refers to. All controls go through a series of events before they are fully initialized. If in some cases you see properties that are not available (and then are), you may be accessing them too soon; or not the right property in the current context (e.g. "Text" versus "Value"). The easiest thing to do is simply display the properties of interest at key points in the program which will give one a better understanding of the "life" of a control.

          A 1 Reply Last reply
          0
          • L Lost User

            I'm not clear on what / when "Otherwise not" refers to. All controls go through a series of events before they are fully initialized. If in some cases you see properties that are not available (and then are), you may be accessing them too soon; or not the right property in the current context (e.g. "Text" versus "Value"). The easiest thing to do is simply display the properties of interest at key points in the program which will give one a better understanding of the "life" of a control.

            A Offline
            A Offline
            ahmed_one
            wrote on last edited by
            #5

            Actually I am referring otherwise to when Form is load but user did not select any date in DateTimePicker and trying to saved the record with default Today's date.

            L 1 Reply Last reply
            0
            • A ahmed_one

              Actually I am referring otherwise to when Form is load but user did not select any date in DateTimePicker and trying to saved the record with default Today's date.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Have you tried binding to "Value" yet?

              A 2 Replies Last reply
              0
              • L Lost User

                Have you tried binding to "Value" yet?

                A Offline
                A Offline
                ahmed_one
                wrote on last edited by
                #7

                Sorry for late reply, Yes I've tried the "Value"... As you've noticed from my code that it's Master/Detail application, and I've create a relation VouchersToVoucherDetails in form code. Before modification of "Value" to DataBindings of vChqDt, vID was showing -1 on form load. But now it is showing null and when try to save the records it say vID cannot be null, and when press ok then no record is save to database.

                1 Reply Last reply
                0
                • L Lost User

                  Have you tried binding to "Value" yet?

                  A Offline
                  A Offline
                  ahmed_one
                  wrote on last edited by
                  #8

                  Hi, problem is solved, I've modified the "Text" and change to "Value", and also add fourth parameter "true" which enable formatting. After which all is going well. Thanks for your guidance and support. Really appreciate. Ahmed

                  L 1 Reply Last reply
                  0
                  • A ahmed_one

                    Hi, problem is solved, I've modified the "Text" and change to "Value", and also add fourth parameter "true" which enable formatting. After which all is going well. Thanks for your guidance and support. Really appreciate. Ahmed

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Glad it's working for you now.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups