locked
How to Automatically increment column value RRS feed

  • Question

  •  

    Hi,

    Whenever a new row is added, i want to keep increment value in one of the column.

    I am able to place default value in one of the column but  i tyring for automatically increment number but fails every time.

    I don't want to use "Identity Specification" in my column.

     

    i Use the following statement for default value of the cell:

     

    Private Sub EmployeeDataGridView_DefaultValuesNeeded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles EmployeeDataGridView.DefaultValuesNeeded

    e.Row.Cells(3).Value = CInt(DnoTextBox.Text)

    End Sub

     

    Thankx.

     

     

    regards

    kashif chotu

     

     

     

     

    Monday, December 3, 2007 8:19 AM

Answers

  •  

    Create your own method to find the highest number of the column and increment it by one.


    The code sample looks to be using a datagridview - so you may want to check the datagridview columns or may want to check the dataset which may be used for databinding. 

     

     

    Tuesday, December 4, 2007 8:33 PM

All replies

  • Hi,

     

    I put a primary key in a table and used Automatically increment of identity value whenever a new is created. I start my "Identity seed=1001". But when i run the form and adding a new record, i found the "Identity seed" starting from zero(0) in the textbox.

     

    I don't what is the problem.

     

    I check the data field properties with the following specification:

     

    Identification Specification  :   Yes

         (Is Identity)                  :    Yes

         Identity Increment        :    1

         Identity Seed               :    1001

     

    From the above everything is correct but whenever form runs i am getting identity with zero.

     

    What is the problem for this solution?

     

    Thankx.

     

     

    Regards

    Kashif Chotu

    Monday, December 3, 2007 6:13 AM
  • Any Solution please?

     

    Monday, December 3, 2007 10:11 AM
  • I'm just guessing here because I haven't actually worked on a program that does what you're describing.

     

    My guess is that the auto increment value isn't generated until you actually add the record to the database.  Do you really need to display this value in your application before the record is added?

     

    Tuesday, December 4, 2007 3:51 AM
  • Yes, i want to generate the values in a textbox automatically whenever a new record is inserted.

     

    This is absolutely necessary for my project. I don't want to type the value in the textbox, i want to keep the textbox in readonly and user's no need to enter the data in the textbox.

     

    Thanks.

     

    Tuesday, December 4, 2007 5:20 AM
  •  

    Create your own method to find the highest number of the column and increment it by one.


    The code sample looks to be using a datagridview - so you may want to check the datagridview columns or may want to check the dataset which may be used for databinding. 

     

     

    Tuesday, December 4, 2007 8:33 PM