Hey all,
I am just recreating a vb6 function that I used to call in another app. I am very new to the whole .NET framework, but I do think there has to be a better way than what I came up with. This function queries a table for an invoice number, returns that invoice number and then increments the table.

This is the code that I got working there's gotta be a better way:

vbcode Code:
  1. Private Function GetInvoiceNo() As Long
  2.  
  3.         sSQL = "SELECT Order_Ctrl_Online from Order_ctrl"
  4.         da = New SqlClient.SqlDataAdapter(sSQL, conn)
  5.         da.Fill(ds, "InvoiceNo")
  6.         GetInvoiceNo = ds.Tables("InvoiceNo").Rows(0).Item(0)
  7.         ds.Tables("InvoiceNo").Rows(0).Item(0) = ds.Tables("InvoiceNo").Rows(0).Item(0) + 1
  8.         sSQL = "Update Order_Ctrl SET Order_Ctrl_Online = Order_Ctrl_Online + 1"
  9.         da = New SqlClient.SqlDataAdapter(sSQL, conn)
  10.         da.UpdateCommand = New SqlCommand(sSQL, conn)
  11.         conn.Open()
  12.         da.UpdateCommand.ExecuteNonQuery()
  13.         conn.Close()
  14.     End Function