Everything was working fine until I added the 4th SQL connection. For some reason I get the error "The ConnectionString property has not been initialized. Line 236: SqlConnection1.Open()". What am I missing? I'm sure there is a more simple way to execute 4 SQL statements one right after the other.
Here is my code:
Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ServerClick
Dim ds2 As New DataSet
Dim sqlCommand3 As New SqlClient.SqlCommand
Dim sqlCommand4 As New SqlClient.SqlCommand
'new sql statement for returning values
SqlSelectCommand2.CommandText = "SELECT Lots.LotNumber as 'Lot Number', Lots.LotDispo as 'Disposition', Lots.LotWeight as 'Weight', Lots.DateShipped as 'Date', Lots.CustomerNumber as 'Customer', Batches.BatchWeight as 'Batch Weight' FROM Lots, Batches where Lots.LotNumber like '" & Left(lotNumber.SelectedItem.Text, 4) & "%" & Mid(lotNumber.SelectedItem.Text, 6, 9) & "%' and Batches.BatchID=Lots.Batch ORDER BY DateShipped;"
DataGrid1.DataSource = SqlSelectCommand2.ExecuteReader
'sql statement to get total LotWeight
sqlCommand3.CommandText = "select sum(LotWeight) from Lots where Lots.LotNumber Like '" & Left(lotNumber.SelectedItem.Text, 4) & "%" & Mid(lotNumber.SelectedItem.Text, 6, 9) & "%'"
sqlCommand3.Connection = SqlConnection1
UsedGrid.DataSource = sqlCommand3.ExecuteReader
UsedGrid.ShowHeader = False
'sql statement to get left weight
sqlCommand4.CommandText = "select sum(Lots.LotWeight)-sum(Batches.BatchWeight) from Lots, Batches where Lots.LotNumber Like '" & Left(lotNumber.SelectedItem.Text, 4) & "%" & Mid(lotNumber.SelectedItem.Text, 6, 9) & "%' =Lots.Batch"
sqlCommand4.Connection = SqlConnection1
LeftGrid.DataSource = sqlCommand4.ExecuteReader
LeftGrid.ShowHeader = False
Label3.Visible = True
Label4.Visible = True
Label5.Visible = True
Label6.Visible = True