Parameterised query question

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I have the following sql for my dataadapter;

SELECT ID, Company, Status
FROM Companies
WHERE Status = @Status

I fill the dataadapter as
Me.CompanyTableAdapter.Fill(Me.MyDataSet.Companies, "Current") and it works
great. The problem is how do I view all Companies and not just the current
ones, when I need to? What changes do I need to make to the SQL and the fill
statement?

Thanks

Regards
 
Not quite sure I understand the question. Are you asking "how do I select
everything, regardless of status"?
If so, then just omit the WHERE clause:

SELECT ID, Company, Status FROM Companies;
 
Change the WHERE clause to something like this:
WHERE @Status IS NULL or @Status = Status

To get all companies, set @Status to DBNull.Value. You could also set a
default value of NULL.
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Yes, sometimes I want to see all records regardless of the status. How do I
omit the where clause? There is only one SELECT SQL associated with the
datadapter. How do I switch between the one with WHERE clause and one
without, when needed?

Thanks

Regards
 
When I call fill like so; Me.CompanyTableAdapter.Fill(Me.MyDataSet.Clients,
"Client", DBNull.Value) to get all records, I get this error; Value of type
'System.DBNull' cannot be converted to 'String'.

Regards
 
On you CompanyTableAdapter you can add one more query without any where
clause, and give a good Method Name.
Use the new Method Name to Fill the DataTable.

JH
 
Back
Top