Click here to Skip to main content
15,883,749 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Private Sub cmdsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsave.Click
        If txtid.Text = "" Or txtname.Text = "" Or txtmn.Text = "" Or txtln.Text = "" Or cbogender.Text = "" Or cbosub.Text = "" Or cbopos.Text = "" Then
            MsgBox("Complete All Fields Needed", MsgBoxStyle.Information, "")
            txtid.Focus()
        ElseIf IsNumeric(txtid.Text) = False Then
            MsgBox("ID number should be numbers only")
        ElseIf sb = True Then
            mycmd.Connection = mycon
            mycmd.CommandText = "insert into `tbluseradmin`(`ID`,`Name`,`MiddleName`,`LastName`,`Gender`,`Subject`,`Position`)values('" & txtid.Text & "','" & txtname.Text & "','" & txtmn.Text & "','" & txtln.Text & "','" & cbogender.Text & "','" & cbosub.Text & "','" & cbopos.Text & "')"
            mycmd.ExecuteNonQuery()
            mycon.Close()
            My.Computer.FileSystem.CopyFile(ofd.FileName, Application.StartupPath & "\images\" & txtid.Text & ".jpg")
            MsgBox("Record Save", MsgBoxStyle.Information, "")
            Call connect()
            Call display()
            Call textboxlocked()
            Call buttonunlock()
            Call cmdlock()
            Call cmd2unlock()
        Else
            mycmd.Connection = mycon
            mycmd.CommandText = "update `tbluseradmin` set`ID`='" & txtid.Text & "',`Name`='" & txtname.Text & "',`MiddleName`='" & txtmn.Text & "',`LastName`='" & txtln.Text & "',`Gender`='" & cbogender.Text & "'where`ID`='" & idnum & "'"
            mycmd.ExecuteNonQuery()
            mycon.Close()
            My.Computer.FileSystem.CopyFile(ofd.FileName, Application.StartupPath & "\images\" & txtid.Text & ".jpg")
            MsgBox("Record Update", MsgBoxStyle.Information, "")
            Call connect()
            Call display()
            Call textboxlocked()
            Call buttonunlock()
            Call cmdlock()
            Call cmd2unlock()


        End If
    End Sub
Posted

1 solution

If your ID column is an auto incrementing identity, then just don't insert it (in the INSERT statement) and the database engine will supply the next value automatically.

If not then try setting it to identity and auto incrmenting first in your table with :
http://stackoverflow.com/questions/17291680/how-to-alter-a-table-for-identity-specification-is-identity-sql-server[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900