AlphaLolz
asked on
Need help adding a query to a datagridview
We have a VB application with a datagridview control on it.
It's connected to a SQL database and displaying the data fine, however we now want to have it only return data that satisfies a specified "select ...." statement.
We can't find an example of how to do this. We need an example. This is Visual Studio 2008 using .Net 3.5. I don't know if that matters though.
Can someone send the code or a pointer to where there is an example of doing this?
We don't want to see how to change what is visible (by hiding rows in the dataview grid) or that sets one dataviewgrid on another. We want to know how to change the data it selects and returns.
We'll take an example in C# if we can translate it.
It's connected to a SQL database and displaying the data fine, however we now want to have it only return data that satisfies a specified "select ...." statement.
We can't find an example of how to do this. We need an example. This is Visual Studio 2008 using .Net 3.5. I don't know if that matters though.
Can someone send the code or a pointer to where there is an example of doing this?
We don't want to see how to change what is visible (by hiding rows in the dataview grid) or that sets one dataviewgrid on another. We want to know how to change the data it selects and returns.
We'll take an example in C# if we can translate it.
ASKER
The issue is that the end-user display choice and what's in place is the gridview.
Personally, I'd rather do it the old-fashioned way (without this data-bound MS creates), but it's what we've been told to use.
Personally, I'd rather do it the old-fashioned way (without this data-bound MS creates), but it's what we've been told to use.
Oh OK. You can then use Datatable.Select/DefaultVi ew.RowFilt er if this is the case. Check this out.
http://programming.top54u.com/post/ASP-Net-DataTable-Select-Rows-using-DefaultView-RowFilter.aspx
http://www.dbtutorials.com/display/dataview-datatable-csharp.aspx
http://programming.top54u.com/post/ASP-Net-DataTable-Select-Rows-using-DefaultView-RowFilter.aspx
http://www.dbtutorials.com/display/dataview-datatable-csharp.aspx
ASKER
It looks to me like this is selecting rows already returned to the initial datagridview.
ASKER
or actually just filtering what to show or not.
What I'm looking for is how to modify the select so that only the rows we want to see are returned from the database in the first place.
What I'm looking for is how to modify the select so that only the rows we want to see are returned from the database in the first place.
OK. Check this out. This might help.
http://forums.asp.net/p/1058769/1514593.aspx#1514593
http://forums.asp.net/p/1010607/1348581.aspx
http://forums.asp.net/p/1058769/1514593.aspx#1514593
http://forums.asp.net/p/1010607/1348581.aspx
ASKER
well, now we're slipping over to gridviews, which are different.
Also one of these is just filtering data in the grid already created.
I think I've found what I was looking for http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx.
Also one of these is just filtering data in the grid already created.
I think I've found what I was looking for http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx.
Oh yeah. Sorry. It is DataGridView. Windows.... I tend to mix those two from time to time. :-)
That is good if you found what you are looking for. Goodluck with your projects. :-)
That is good if you found what you are looking for. Goodluck with your projects. :-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why don't you just use a stored procedure to deal with the select statement and use a data reader to read the results of a stored procedure?
You can do it something like this as an example
Public Function GetSelectResult(ByVal Param1 as string, ByVal Param2 as string) As Boolean
Dim DR As SqlClient.SqlDataReader
Dim Conn As New SqlClient.SqlConnection(<y
Dim Cmd As New SqlClient.SqlCommand("usp_
Try
If Conn.State <> ConnectionState.Open Then
Conn.Open()
End If
Cmd.CommandType = CommandType.StoredProcedur
Cmd.Connection = Conn
Cmd.Parameters.AddWithValu
Cmd.Parameters.AddWithValu
DR = Cmd.ExecuteReader()
While DR.Read()
''Read you data reader here.
End While
DR.Close()
Return True
Catch ex As Exception
_ErrorDescription = "Error retrieving All Details: " & ex.Message & _
" - " & ex.Source & " - " & ex.StackTrace
Return False
Finally
If Conn.State = ConnectionState.Open Then
Conn.Close()
End If
End Try
End Function