Reputation: 133
I have a form where i want to enter Sr. Nos for machines.it have a combo box where i have to choose the invoice no saved in another table along with its corresponding qty of machines. When i am entering machine details it should say me as "enter Sr no. for X'th/Y'th machine where y is the total qty saved in db and x is the no. of sr no. i have saved+1 "
It should also allow me to save the no. some where.. i mean in any variable so that if i pause my work in between and after word if continue it should say me "enter detail for X'th/Y'th" not "1'st/Y'th"
I am using this code:
Private Sub get_qty()
Dim qtySql As String = "SELECT * FROM invoice1 where chalan_no='" & cmbChal_no.Text & "'"
cnnOLEDB.Open()
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(qtySql, cnnOLEDB)
Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader
If dr.Read = True Then
qnty = dr("qty")
End If
cnnOLEDB.Close()
End Sub
Private Sub Srno_enter()
Dim noSql As String = "SELECT count(sr_no) FROM Vendor_machine GROUP BY(chalan_no) having chalan_no='" & cmbChal_no.Text & "'"
cnnOLEDB.Open()
Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(noSql, cnnOLEDB)
' Suggest code retrieve count(sr_no) <--------------------------
cnnOLEDB.Close()
End Sub
private sub show()
lblMachine= 'Result of count(sr_no)' "/" qnty
end sub
Please suggest me the code for same.. thank you..
Upvotes: 0
Views: 97
Reputation: 27342
Just use an Identity column in your database and let the database engine do the work of creating the next free number.
If you wrote a stored procedure to do the insert, you could return the serial number as an output parameter
Upvotes: 1