Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 9th, 2004, 03:44 PM
Authorized User
 
Join Date: May 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default whereclause use in a Data Grid

I have a datagrid that needs to display records given by a Select statement with a WHERE clause that is passed in a given value by variable 'appID'. For some reason I've been unable to make it work any which way I tried.

As I'm not totally sure how to effectively pass a value in the context of a SQL Adapter to the DB, The last thing I tried was passing it to a variable and then to the SQL string. The compiler screams with the error:
Quote:
quote:
BC30311: Value of type 'String' cannot be converted to 'System.Data.SqlClient.SqlCommand'.
Has anyone ever tried this?? I've looked around and most data bound to datagrids are usually simple queries, i.e., "Select * From Clients" with no filtering whatsoever.

Here's some code:



Sub BindGrid()
        Dim dsAppl As DataSet
        Dim conMeta As SqlConnection
        Dim dadAppl As SqlDataAdapter
        Dim whereClause As String = "WHERE Application_ID = '"&session("appID")&"' "

        dsAppl = New DataSet()
        conMeta = New SqlConnection( "Server='DOHSDBS96';trusted_connection=true;Databa se='METADATAv2'" )
        dadAppl = New SqlDataAdapter( "SELECT *, Q.Type AS QType, S.Type AS SType FROM A_Table A_T INNER JOIN Quality Q ON Q.Quality_ID=A_T.Quality_ID INNER JOIN Status S ON S.Status_ID=A_T.Status_ID" & whereClause & "ORDER BY & viewstate("sortField").ToString() & " " & viewstate("sortDirection").ToString(), conMeta )
        dadAppl.Fill( dsAppl,"A_Table" )
        Try
            AppDataGrid.DataSource = dsAppl
            AppDataGrid.Databind()
        Catch exc As Exception
            Response.Write(exc)
            AppDataGrid.CurrentPageIndex = 0
        End Try
        ShowStats
End Sub
 

 
Old August 10th, 2004, 07:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

You know the where clause runs in with A_T.Status_ID, so it would appear as:

INNER JOIN Status S ON S.Status_ID=A_T.Status_IDWHERE Application_ID =

Put a space before the where clause.

Brian
 
Old August 10th, 2004, 08:30 AM
Authorized User
 
Join Date: May 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried it with:

...Status_ID Where Application_ID = '55' ...

but got the same error:

Value of type 'String' cannot be converted to 'System.Data.SqlClient.SqlCommand'.




 
Old August 10th, 2004, 09:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

viewstate("sortDirection").ToString(), conMeta )

This may be the problem.

Take a look at this:
http://samples.gotdotnet.com/quickst...fdatagrid1.src

My advice would be to SELECT * FROM table_name and see if you are connecting, then add all the rest.

 
Old August 11th, 2004, 07:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Also noticed no ending quote after order by:
Code:
"ORDER BY " & viewstate("sortField")...
In addition, if you are still getting that error, try putting the entire SQL string into a sql command as such:
Code:
objAdapter = new SQLDataAdapter(New SQLCommand("select ..."), conMeta)
Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
Export data from data grid to excel pomoc VB.NET 2002/2003 Basics 0 December 16th, 2005 03:11 PM
Export data from data grid to Excel pomoc Visual Basic 2005 Basics 0 December 16th, 2005 02:56 PM
Problems with whereclause blaabil Classic ASP Databases 7 July 14th, 2005 11:20 AM
trying to load db data into data grid itsajourney Beginning VB 6 2 June 7th, 2005 12:05 PM
Generate reports from Listbox Or WhereClause help nkrukovsky Access VBA 1 November 6th, 2003 06:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.