Help With SQL Query

bemis82

Member
Joined
Jun 4, 2011
Messages
14
Programming Experience
Beginner
Hey all, I wrote a query in .net where i would like it to only choose Clean Slots that are completely full with all of the items that go in there. Even if one item that is supposed to go into that particular clean slot is not updated with a "Returned_To_Clean_Slot" timestamp then i don't want to see that clean slot record. Another way to look at it would be I would like to see all the clean slots where all of the items that are supposed to go into that clean slot have been updated with a "Returned_To_Clean_Slot" Timestamp. The other basic criteria I have for this query is where the transaction_item_status = 'Pending' and the Item_Name <> to 'DryClean'. Currently I have records in my table that should be showing up when this query is run but it still comes up empty. Any help would be great! Below is what i have so far.


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 Distinct Clean_Slot from transaction_inventory WHERE Transaction_Item_Status = 'Pending' And Item_Name <> 'DryClean' And not exists(select 1 from transaction_inventory where Returned_To_Clean_Slot = '')"
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)
DataGridView3.DataSource = Table
mydata = mycommand.ExecuteReader()
mydata.Close()
SQLConnection.Close()

Catch ex As Exception
SQLConnection.Close()
'TransparentForm.Show()
'NoSQLConnection.Show()
MsgBox(ex.ToString)
End Try

 
Have you tried the query outside of .NET? Do you have access to the management tools for the SQL server? If so, it's a lot easier to debug.

Also, why do you have a datareader created? It's doing nothing in your example.
 
Yea i tried the query in phpmyadmin as well and the query was not working correctly there either. However i kept working on it and i was able to get it figured out. Thanks for the help though.
 
Back
Top