Which checks the tbl_batches table against a Customer ID to see of they have a current Batch Number in the system. If they do it adds one to this figure or returns 1 if the customer does not have any batches.
I'm now in the process of converting this database to VB.NET and I'm having issues trying to do the same thing.
I currently have:
Dim con As New SqlConnection Dim cmd As New SqlCommand Try con.ConnectionString = My.Settings.TestValue() con.Open() cmd.Connection = con txtBatchNumber = 1 + Nz(DMax("batch_number", "tbl_batches", "customer_id = '" & customer_id.text & "'"), 0) Dim customer_id, batch_number, batch_reference, create_date As String customer_id = txtCustomerNumber.Text batch_number = txtBatchNumber.Text batch_reference = txtBatchReference.Text create_date = Date.Today cmd.CommandText = "INSERT INTO tbl_batches([customer_id], [batch_number], [batch_reference], [create_date]) VALUES('" & customer_id & "', '" & batch_number & "', '" & batch_reference & "', '" & create_date & "')" cmd.ExecuteNonQuery() Catch ex As Exception MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records") Finally con.Close() End Try End Sub