469,883 Members | 1,177 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,883 developers. It's quick & easy.

DataAdapter Select with Parameters

I have the following:

* An OLEDBCommand with command text "SELECT CAMPAIGN,
DAY_OUT WHERE (CAMPAIGN LIKE '@campaign')"
* A DataAdapter that point the select to the above command
* A data grid that I use to display the data
* form load code to populate the controls:
DsCampaign1 = New DataSet
cmdProActiTmp_Sel.Parameters.Item("@Campaign").Val ue = _
Trim(txtcampaign.Text())
DataAdapter1.Fill(DsCampaign1)
DataGrid1.SetDataBinding(DataAdapter1, _
cmdProActiTmp_Sel.ToString)

The issue:

I always get a zero result set, regardless of what the
value of txtcampaign.
TxtCampaign is null when the form first loads but changes
based upon events on the form. How do I get the datagrid
to refresh and use the value?
Nov 20 '05 #1
6 4597
In the absence of a DataBind() statement, I assume you are using Windows
Forms. If this is the case, the bound data will be reflected in the DataGrid
each time it is changed.

Your problem, looks as if its more related to the data you are selected. For
a test, try hard coding the select statement to retreive known ' or all '
values and then take it from there.

HTH

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Jack" <Ja**@sonomaenterprises.com> wrote in message
news:25*****************************@phx.gbl...
I have the following:

* An OLEDBCommand with command text "SELECT CAMPAIGN,
DAY_OUT WHERE (CAMPAIGN LIKE '@campaign')"
* A DataAdapter that point the select to the above command
* A data grid that I use to display the data
* form load code to populate the controls:
DsCampaign1 = New DataSet
cmdProActiTmp_Sel.Parameters.Item("@Campaign").Val ue = _
Trim(txtcampaign.Text())
DataAdapter1.Fill(DsCampaign1)
DataGrid1.SetDataBinding(DataAdapter1, _
cmdProActiTmp_Sel.ToString)

The issue:

I always get a zero result set, regardless of what the
value of txtcampaign.
TxtCampaign is null when the form first loads but changes
based upon events on the form. How do I get the datagrid
to refresh and use the value?

Nov 20 '05 #2
I removed the where clause and it returns all the records
with out error.

This is a windows application (not web), it a windows form
with a datagrid on the form.

I am sure once I understand the details of data access
in .NET it will be an improvement from V6, but right now
this is sooo frustrating. I spend hours getting basic
things working that took minutes in v6.......

-----Original Message-----
In the absence of a DataBind() statement, I assume you are using WindowsForms. If this is the case, the bound data will be reflected in the DataGrideach time it is changed.

Your problem, looks as if its more related to the data you are selected. Fora test, try hard coding the select statement to retreive known ' or all 'values and then take it from there.

HTH

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Jack" <Ja**@sonomaenterprises.com> wrote in message
news:25*****************************@phx.gbl...
I have the following:

* An OLEDBCommand with command text "SELECT CAMPAIGN,
DAY_OUT WHERE (CAMPAIGN LIKE '@campaign')"
* A DataAdapter that point the select to the above command * A data grid that I use to display the data
* form load code to populate the controls:
DsCampaign1 = New DataSet
cmdProActiTmp_Sel.Parameters.Item("@Campaign").Val ue = _
Trim(txtcampaign.Text())
DataAdapter1.Fill(DsCampaign1)
DataGrid1.SetDataBinding(DataAdapter1, _
cmdProActiTmp_Sel.ToString)

The issue:

I always get a zero result set, regardless of what the
value of txtcampaign.
TxtCampaign is null when the form first loads but changes based upon events on the form. How do I get the datagrid to refresh and use the value?

.

Nov 20 '05 #3
OK, I think I see what your trying to do then.

So, on the event for textChanged or under a button

Dim SQLString = "SELECT . .. . . . . . .
DataAdapter.Clear()
DataAdapter.Fill( DataSet, TableName )

You dont need to rebind it.

Then is should be a simple matter of tuning your select statement.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"jack" <ja**@sonomaenterprises.com> wrote in message
news:25*****************************@phx.gbl...
I removed the where clause and it returns all the records
with out error.

This is a windows application (not web), it a windows form
with a datagrid on the form.

I am sure once I understand the details of data access
in .NET it will be an improvement from V6, but right now
this is sooo frustrating. I spend hours getting basic
things working that took minutes in v6.......

-----Original Message-----
In the absence of a DataBind() statement, I assume you

are using Windows
Forms. If this is the case, the bound data will be

reflected in the DataGrid
each time it is changed.

Your problem, looks as if its more related to the data

you are selected. For
a test, try hard coding the select statement to retreive

known ' or all '
values and then take it from there.

HTH

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Jack" <Ja**@sonomaenterprises.com> wrote in message
news:25*****************************@phx.gbl...
I have the following:

* An OLEDBCommand with command text "SELECT CAMPAIGN,
DAY_OUT WHERE (CAMPAIGN LIKE '@campaign')"
* A DataAdapter that point the select to the above command * A data grid that I use to display the data
* form load code to populate the controls:
DsCampaign1 = New DataSet
cmdProActiTmp_Sel.Parameters.Item("@Campaign").Val ue = _
Trim(txtcampaign.Text())
DataAdapter1.Fill(DsCampaign1)
DataGrid1.SetDataBinding(DataAdapter1, _
cmdProActiTmp_Sel.ToString)

The issue:

I always get a zero result set, regardless of what the
value of txtcampaign.
TxtCampaign is null when the form first loads but changes based upon events on the form. How do I get the datagrid to refresh and use the value?

.

Nov 20 '05 #4
Split the problem into two parts:
- figure out how to get the grid to change when the query changes (see the
post by OHM)
- verify that the query is changing with the appropriate parameter

"Jack" <Ja**@sonomaenterprises.com> wrote in message
news:25*****************************@phx.gbl...
I have the following:

* An OLEDBCommand with command text "SELECT CAMPAIGN,
DAY_OUT WHERE (CAMPAIGN LIKE '@campaign')"
* A DataAdapter that point the select to the above command
* A data grid that I use to display the data
* form load code to populate the controls:
DsCampaign1 = New DataSet
cmdProActiTmp_Sel.Parameters.Item("@Campaign").Val ue = _
Trim(txtcampaign.Text())
DataAdapter1.Fill(DsCampaign1)
DataGrid1.SetDataBinding(DataAdapter1, _
cmdProActiTmp_Sel.ToString)

The issue:

I always get a zero result set, regardless of what the
value of txtcampaign.
TxtCampaign is null when the form first loads but changes
based upon events on the form. How do I get the datagrid
to refresh and use the value?

Nov 20 '05 #5
The one thing that I do not understand is how the
parameters are used. Do I just build the sql stmt
with '"where campaign = " & trim(textbox.text)' and use
that in place of the table name and not worry about the
parameters.
-----Original Message-----
OK, I think I see what your trying to do then.

So, on the event for textChanged or under a button

Dim SQLString = "SELECT . .. . . . . . .
DataAdapter.Clear()
DataAdapter.Fill( DataSet, TableName )

You dont need to rebind it.

Then is should be a simple matter of tuning your select statement.
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"jack" <ja**@sonomaenterprises.com> wrote in message
news:25*****************************@phx.gbl...
I removed the where clause and it returns all the records with out error.

This is a windows application (not web), it a windows form with a datagrid on the form.

I am sure once I understand the details of data access
in .NET it will be an improvement from V6, but right now
this is sooo frustrating. I spend hours getting basic
things working that took minutes in v6.......

>-----Original Message-----
>In the absence of a DataBind() statement, I assume you

are using Windows
>Forms. If this is the case, the bound data will be

reflected in the DataGrid
>each time it is changed.
>
>Your problem, looks as if its more related to the data

you are selected. For
>a test, try hard coding the select statement to retreive
known ' or all '
>values and then take it from there.
>
>HTH
>
>--
>
>OHM ( Terry Burns )
> . . . One-Handed-Man . . .
>
>Time flies when you don't know what you're doing
>
>"Jack" <Ja**@sonomaenterprises.com> wrote in message
>news:25*****************************@phx.gbl...
>> I have the following:
>>
>> * An OLEDBCommand with command text "SELECT CAMPAIGN,
>> DAY_OUT WHERE (CAMPAIGN LIKE '@campaign')"
>> * A DataAdapter that point the select to the above

command
>> * A data grid that I use to display the data
>> * form load code to populate the controls:
>> DsCampaign1 = New DataSet
>> cmdProActiTmp_Sel.Parameters.Item("@Campaign").Val ue

= _ >> Trim(txtcampaign.Text())
>> DataAdapter1.Fill(DsCampaign1)
>> DataGrid1.SetDataBinding(DataAdapter1, _
>> cmdProActiTmp_Sel.ToString)
>>
>> The issue:
>>
>> I always get a zero result set, regardless of what the >> value of txtcampaign.
>> TxtCampaign is null when the form first loads but

changes
>> based upon events on the form. How do I get the

datagrid
>> to refresh and use the value?
>
>
>.
>

.

Nov 20 '05 #6
Hi Jack,

I can not completly see how you use the commands, can you try this sample I
made for you?

\\\
cmd.CommandText = "Select * from tblUsers where (UserId = @UserId)"
Dim myparam As New OleDb.OleDbParameter("@UserId", _
OleDb.OleDbType.Integer)
myparam.Value = 1
cmd.Parameters.Add(myparam)
///
I hope this helps?

Cor
The one thing that I do not understand is how the
parameters are used. Do I just build the sql stmt
with '"where campaign = " & trim(textbox.text)' and use
that in place of the table name and not worry about the
parameters.

Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Joe Fetters via .NET 247 | last post: by
1 post views Thread by James | last post: by
2 posts views Thread by John Smith | last post: by
8 posts views Thread by Zorpiedoman | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.