I am developing a simple savings account application where I am able to simulate deposit, withdrawal and transfer of money. I have a button called "Deposit" that I can click and data will be recorded in my database.
To make that insert statement I am using SQL parameters and this is the code:
SqlCon = New SqlConnection
SqlCon.ConnectionString = "............"
Try
Query = "INSERT INTO Transacoes(tpAccount, dateTransaction, descrTransaction, amoutTransaction, balanceTransaction)
VALUES(@tpAccount, @dateTransaction, @ddescrTransaction, @amoutTransaction, @balanceTransaction)"
SqlCon.Open()
SqlCmd = New SqlCommand(Query, SqlCon)
With SqlCmd.Parameters
.Add("@tpAccount", SqlDbType.Char).Value = cbTipoConta.Text
.Add("@dateTransaction", SqlDbType.DateTime).Value = txtDate.Text
.Add("@descrTransaction", SqlDbType.Char).Value = cmdDepositar.Text
.Add("@amoutTransaction", SqlDbType.Int).Value = txtDeposito.Text
.Add("@balanceTransaction", SqlDbType.Int).Value = txtBalance.Text
End With
SqlCmd.ExecuteNonQuery()
SqlCon.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
In this table I have an "ID" column but I don't want it to display on SQL parameters and shows me an error:
Cannot insert the value NULL into column 'Id'`.
I should autoincrement the Id and then this will work fine? Or what is the best way to solve this?