Dear sir,
I need a help. am having problem coding in vb.net. I have created a field which automatically in sql server.
I want a code in vb.net so that user the text on the get focus, the automber would display the current no on the form.
This autonumber is primary key in table1(tran_head) and as foreign key in table2(trans_Detail).
I want another so that when the data is saved, it would automatially update the second table with current automber displayed.

thanks

make a procedure to select the last number on tran_head and add it with 1..that a autonumber logic..

the loan_no is read only, the field preceeding the loan is the msddate_applied.
so when this field loses, it should display the current loan_no in the textbox on the form.
please check if mycode is correct.
Private Sub msdDate_Applied_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles msdDate_Applied.LostFocus
Dim loan_no As Integer
put = "SELECT max(loan_no) FROM trans_head"
loan_no = (txtLoan_no.Text + 1)
End Sub
thanks
jmensah

After modifying code below, am getting the error durng runtime 'conversion from string "" to type 'Double' is not valid

Private Sub msdDate_Applied_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles msdDate_Applied.LostFocus
Dim loan_no As Integer
Dim mySqlDBConnection As New SqlConnection(ConnectionString)
Dim mySqlDBCommand As New SqlCommand(put, mySqlDBConnection)
put = "SELECT max(loan_no) FROM Loan"
loan_no = (txtLoan_no.Text + 1)
Dim myDataReader As SqlDataReader = mySqlDBCommand.ExecuteReader
txtLoan_no.Text = myDataReader.Item(loan_no).Tointeger
End Su

...am getting the error durng runtime 'conversion from string "" to type 'Double' is not valid

The following will throw the "Conversion from string "" to type 'Double' is not valid." error.

Private x As String = ""
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        x += 1
        MsgBox(x)
    End Sub

To solve this issue, you will need to check the value and make sure it is not a empty value before it has to be modified.

Private x As String = ""
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If x = "" Then x = "0" '// if empty, add a value.
        x += 1
        MsgBox(x)
    End Sub

Hope this helps.

Edited 5 Years Ago by codeorder: n/a

the code worked, it display the autono 1, but instead of displaying in the text box, it displayed as message box. I want it displayed in the textbox

thanks it worked perfectly, but will it update the trans_detail table automatically as foregn key in that table

This question has already been answered. Start a new discussion instead.