We help IT Professionals succeed at work.

VB.net equivalent to VBA coder

889 Views
Last Modified: 2014-05-09
Hi,

I have the following code in an Access database:

Me.batch_number = 1 + Nz(DMax("batch_number", "tbl_batches", "customer_id = '" & Me.customer_id & "'"), 0)
Me.create_date = Date
Me.batch_reference = Me.customer_id & "-" & Me.batch_number
Me.cd_reference = "CD" & Me.customer_id & "-" & Me.batch_number

Open in new window


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

Open in new window


However the  Nz(DMax is obviously not a VB.NET expression

Hope someone can help.
Comment
Watch Question

Simple Geek from the '70s
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Looks like it will be the stored procedure route for me then.

Author

Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for anthonytr's comment #a40053172
Assisted answer: 250 points for ve3ofa's comment #a40052459
Assisted answer: 250 points for JamesBurger's comment #a40052854

for the following reason:

.

Author

Commented:
.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.