This is my first "from scratch" database application, so I'm not sure if I'm going about things in the best manner and would appreciate any advice/suggestions, even inor quibbles. I'm using Visual Basic 2010 Pro and our primary database is SQL Server 2000, though it will hopefully be upgraded to 2008 in the near future, and this application will likely end up being used by other branches that already utilize 2008.
Everything works fine, for the most part, I just want to make sure I'm not doing anything "bad".
I have the following variables declared publicly:
I have a public function named GetConnect that sets the connection string specify to the situation (there are a few times when data needs to be pulled from a different database within the same server) in the form of:Code:Public Conn As SqlConnection Public Reader As SqlDataReader Public User As New UserData 'Class containing the username, password and privilege levels Public Connect As New ConnectInfo 'Class containing the servername and various database names Public SQLQuery As New SqlCommand
And here is one of my several dozen database accessing procedures:Code:Conn = New SqlConnection("Data Source=" & Connect.Server & ";Initial Catalog=" & Connect.AppName & ";User Id=" & User.Username & ";Password=" & User.Password & ";")
Is there anything glaringly wrong with any of this code?Code:Public Sub PopulateCustomers(ComboBox As ComboBox) Dim daCustomers As New SqlDataAdapter Dim dsCustomers As New DataSet Try Conn = GetConnect() SQLQuery = Conn.CreateCommand SQLQuery.CommandText = "SELECT Customer_Name, Customer_ID FROM Customer_Information ORDER BY Customer_Name" daCustomers.SelectCommand = SQLQuery daCustomers.Fill(dsCustomers, "Customer_Information") With ComboBox .DataSource = dsCustomers.Tables("Customer_Information") .DisplayMember = "Customer_Name" .ValueMember = "Customer_ID" .SelectedIndex = -1 End With Catch ex As Exception MessageBox.Show("Error: " & ex.Source & ": " & ex.Message, "Connection Error", MessageBoxButtons.OK) Finally Conn.Close() End Try End Sub




Reply With Quote