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:
Private Function GetInvoiceNo() As Long sSQL = "SELECT Order_Ctrl_Online from Order_ctrl" da = New SqlClient.SqlDataAdapter(sSQL, conn) da.Fill(ds, "InvoiceNo") GetInvoiceNo = ds.Tables("InvoiceNo").Rows(0).Item(0) ds.Tables("InvoiceNo").Rows(0).Item(0) = ds.Tables("InvoiceNo").Rows(0).Item(0) + 1 sSQL = "Update Order_Ctrl SET Order_Ctrl_Online = Order_Ctrl_Online + 1" da = New SqlClient.SqlDataAdapter(sSQL, conn) da.UpdateCommand = New SqlCommand(sSQL, conn) conn.Open() da.UpdateCommand.ExecuteNonQuery() conn.Close() End Function




Reply With Quote