i want my order id to be autoincremented and stored in textbox and when i hit click, it gets stored in datagridview, so i can save my order in bulk from datagridview again.

my code have some issue

'i put this on formload (order page)
Dim order As String
            Dim leftinv As String
            Dim rightinv As String
            
            Dim cmdorder As OleDbCommand = New OleDbCommand("SELECT * from order", con)

            Dim dsorder As New DataSet
            Dim daorder As New OleDbDataAdapter

            daorder.SelectCommand = cmdorder

            daorder.Fill(dsorder, "order")

            order = dsorder.Tables("order").Rows(0).Item("orderID")

            leftinv = Microsoft.VisualBasic.Left(order, 5) 'first 5 char is TESTS
            rightinv = leftinv & Format(Microsoft.VisualBasic.Right(order, 5) + 1, "00000") ' last five 00001 

 txtOrderID.Text = rightinv

.
my textbox gets executed properly. however when i hit the add button to add it to datagridview, instead of recording TESTS0002 it adds TESTS0003, and with each 'addbutton hit' the entire columns content of orderID gets the latestes incremented value.

how do i fix this?
also i would like to know THE CODE TO GET THE LAST NUMBER added to orderID field in order table.

in my add button code, i take the value of txtOrderID.text for the orderID column value

Help

Recommended Answers

All 3 Replies

If you hit the button again does is the value TEST0005 entered (i.e. it always increment by 2)? If it keeps repeating like that the code you use to increment the text box is probably getting called when the button is clicked. Do you have it in the page_load function by any chance?

the counter is correct, but the problem is, the latest increment is always shown in the entire column of the datagridview instead of giving unique id for each. eg

with the fourt order entry, the texbox have value test0005

serial, productid, orderID
1 ------- 1 ------- TEST0005
2 ------- 2 ------- TEST0005
3 ------- 3 ------- TEST0005
4 ------- 1 ------- TEST0005

while desired output is

serial, productid, orderID
1 ------- 1 ------- TEST0002
2 ------- 2 ------- TEST0003
3 ------- 3 ------- TEST0004
4 ------- 1 ------- TEST0005

y not you are using concatenation for this , i cant understand your question , but i assume that if you press add button then the line will add in your giving format ,

'code this on the click event of your button
datagrid1.rows.add(txtserialno.text,txtproductid.text,"TEST0000"& textorderid.text)

if please you can rephrase your question then i can help you in much better way

Regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.