PC Review


Reply
Thread Tools Rate Thread

dataset and where clause

 
 
Altman
Guest
Posts: n/a
 
      26th Jun 2006
I am playing around with making a dataset with the designer in vb.net
2005. I realize you can add parameters to select statement and then
filter off of those parameters. What I would like to do is to take the
dataset that the designer made and add the whole where clause to it at
run time. Is this possible?

 
Reply With Quote
 
 
 
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      26th Jun 2006
Altman,

I don't think so, the designer builds beside the Select as well the Update,
the Insert and the Deletecommands.

Those are more complex than the standards, because for concurrencychecking
are the old rows first checked against the last in the database.

If you want to do things like you ask, than you should in my opinion forget
the designer and do everything in code.

Just my idea.

Cor

"Altman" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
>I am playing around with making a dataset with the designer in vb.net
> 2005. I realize you can add parameters to select statement and then
> filter off of those parameters. What I would like to do is to take the
> dataset that the designer made and add the whole where clause to it at
> run time. Is this possible?
>



 
Reply With Quote
 
 
 
 
Altman
Guest
Posts: n/a
 
      26th Jun 2006
Thanks for the reply, the reason I would like to do this with the
designer is I plan to use the rdlc. In order to make the rdlc I need a
dataset to design it off of. But as I said before I would like to set
the where clause programatically. I know I can filter the dataset
table but I would like to filter it on the select statement to speed
things up.

 
Reply With Quote
 
=?Utf-8?B?UmljaA==?=
Guest
Posts: n/a
 
      26th Jun 2006
I think you are confusing dataset with dataAdapter. The dataAdapter is the
component that contains/uses the sql statements. You have the 4 basic sql
commands "Select", "Insert", "Update", "Delete" that are part of the
dataAdapter. Note: it is way better/easier to write out the
dataAdapters/datasets than to use the designer. Here is a sample:

Imports System.Data.SqlClient

sub something()
Dim da As sqlDataAdapter, ds As Dataset, conn As Sql Connection
conn = New SqlConnection
conn.ConnectionString = "Data
Source=yourserver;UID=yourID;PWD=yourpassword;DATABASE=someDB"
da = New sqlDataAdapter
ds = New Dataset
da.SelectCommand = New SqlCommand
da.SelectCommand.Connection = conn
da.SelectCommand.CommandText = "Select * from tbl1 Where RecordID = @ID"
da.SelectCommand.Parameters.Add(New SqlParameter("@ID", SqlDBType.Int, 4,
"RecordID")

da.SelectCommand.Parameter("@ID").Value = txtRecordID.Text

da.Fill(ds, "tbl1")
Datagridview1.Datasource = ds.Tables("tbl1")
End Sub

Now your dataset contains a table called "tbl1" which is a copy of the table
from the database -- except in memory and gets displayed in the datagridview.

HTH,
Rich

"Altman" wrote:

> I am playing around with making a dataset with the designer in vb.net
> 2005. I realize you can add parameters to select statement and then
> filter off of those parameters. What I would like to do is to take the
> dataset that the designer made and add the whole where clause to it at
> run time. Is this possible?
>
>

 
Reply With Quote
 
Altman
Guest
Posts: n/a
 
      26th Jun 2006
I do understand the difference between a dataadatper and a dataset. I
am trying to make a rdlc report and as far as I can tell, I cannot use
a dataset that is created programatically. Therefore I was using the
designer to make a dataset. Obviously the dataset that is created with
the designer must create it's own dataadapter to pull the data in. I
basically just need to access this adapter, and either change the sql
select or at the very least obtain what the sql select is. Unless
someone knows of an easier way that I can design a rdlc and be able to
set the where clause programatically.

 
Reply With Quote
 
Jim Wooley
Guest
Posts: n/a
 
      26th Jun 2006
You can use the CommandBuilder object to build the update, insert and delete
commands as necessary based on a select command. Naturally, you will suffer
some performance implications in doing this. See http://msdn.microsoft.com/library/de...andbuilder.asp.
The CommandBuilder is used by the VS designer to create the commands. I would
recommend NOT using it in a production application, but rather have more
fine-grained control of your environment.

Per the original question, you should be able to check the DataAdapter.SelectCommand.CommandText
to manipulate the SQL being sent. One thing to remember: use parameterized
queries not string concatenation to avoid SQL Injection.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx

> Altman,
>
> I don't think so, the designer builds beside the Select as well the
> Update, the Insert and the Deletecommands.
>
> Those are more complex than the standards, because for
> concurrencychecking are the old rows first checked against the last in
> the database.
>
> If you want to do things like you ask, than you should in my opinion
> forget the designer and do everything in code.
>
> Just my idea.
>
> Cor
>
> "Altman" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
>
>> I am playing around with making a dataset with the designer in vb.net
>> 2005. I realize you can add parameters to select statement and then
>> filter off of those parameters. What I would like to do is to take
>> the dataset that the designer made and add the whole where clause to
>> it at run time. Is this possible?
>>



 
Reply With Quote
 
Bob
Guest
Posts: n/a
 
      26th Jun 2006
When you create a bound datagridview on a form you will see that doing that
creates three objects a dataset a binding source and a table adatapter. In
the binding source you will find a property called filter. This is basically
where you can enter a value that is everything you would find in a where
clause except the Where keyword
In your code you can write a sequence that does the following
1- clears the dataset or maybe just the datatable you want to use
2- Sets the filter on the bindingsource
3- Fill the tabledapter(s)
Lets say you have dataset1, that would give you Bindingsource1 and
datatable1 and your sql table itself is named Table1

You would do something like
dataset1.clear 'This clears all the data from all the rows in the dataset
If you want to be able to refill just a single table one at a time, you can
set the tableadapter's ClearBeforeFill property to true.
When you do that each time you call for a fill on a tableadapter it will
automatically clear that table adapter's content.

BindingSource1.filter = "Myfield1 = 'a string' and Myfield2 = 2"
TableAdapter1.fill(dataset1.table1)

You can put this in the form load event (in which case you don't need the
dataset1.clear statement) or you can do this in any event like a button
click. I spoke about the datagridview but basically any bound control on
your form will need to use the same three objects, dataset bindingsource and
table adapter.

HTH

Bob




"Altman" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am playing around with making a dataset with the designer in vb.net
> 2005. I realize you can add parameters to select statement and then
> filter off of those parameters. What I would like to do is to take the
> dataset that the designer made and add the whole where clause to it at
> run time. Is this possible?
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Top Clause with GROUP BY clause? Dan Microsoft Access Queries 2 17th Dec 2008 08:27 PM
Can I use a between clause or in clause on an IF statement =?Utf-8?B?c3NjaWFycmlubw==?= Microsoft Excel Programming 2 4th May 2007 04:48 PM
Take out the Retail EULA transfer only once Clause and WGAN and many legitimate customers will be pleased SESSION_EVENT Windows Vista General Discussion 33 1st Nov 2006 09:45 PM
WHERE clause returns A and B, but not A and C =?Utf-8?B?YWFlYXJoYXJ0?= Microsoft Access Queries 4 5th Jan 2006 01:39 PM
Is this a bug? The Where Clause behaves differently in the Fill Dataset and the Select Command msnews.microsoft.com Microsoft C# .NET 1 2nd Nov 2004 12:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:10 AM.