Hey All, quick SQL related question, i have transaction table that has all of the bag and item related fields for my business. Each transaction can have multiple Bags and each Bag has it's own skew number. Where it gets a little tricky is that we re-use the bags so over time they can show up in many transactions. Now what i'm trying to do is to search for all of the records in all of the transactions that a particular bag was in. However if I just run they query normally I will get all of the transactions that a bag was in, but not all of the records of all of the transactions that that particular bag was in because there were other records in the transaction that had different stuff in it. Below is what i have so far but it doesnt work because it errors out if there is more then 1 transaction number in the sub query. I was thinking of making a temporary table with all of the transaction numbers a bag would bring up and then run a select query joining it by transaction number so i get all of the records associated with those transactions but i've been having trouble doing that. Any suggestions or help would be really appreciated.
Thanks, below is what i have so far...
Thanks, below is what i have so far...
VB.NET:
Public Sub TransactionInventory()
SQLConnection.ConnectionString = connectionstring
Try
SQLConnection.Close()
If SQLConnection.State = ConnectionState.Closed Then
SQLConnection.Open()
End If
Dim Now As DateTime = DateTime.Now
Dim sqlquery = "Select * from transaction_inventory where Transaction_Number = (Select Transaction_Number From transaction_inventory Where Bag_Skew = '" & TextBox1.Text & "')
transaction_inventory.transaction_number = selected_transactions.transaction_number"
Dim mycommand As New MySqlCommand()
Dim myadapter As New MySqlDataAdapter()
Dim table As New DataTable
mycommand.Connection = SQLConnection
mycommand.CommandText = sqlquery
myadapter.SelectCommand = mycommand
Dim mydata As MySqlDataReader
myadapter.Fill(table)
DataGridViewAllTransactionInventory.DataSource = table
mydata = mycommand.ExecuteReader()
mydata.Close()
SQLConnection.Close()
Catch ex As Exception
SQLConnection.Close()
MsgBox(ex.ToString)
End Try