PC Review


Reply
Thread Tools Rate Thread

ADO.NET + VB.NET = Confusion

 
 
James
Guest
Posts: n/a
 
      7th Jan 2004
So far, is basically dispise ADO.NET & VB.NET. Here's why:

Too many confusing ways to do simple things. Here are two
examples that maybe someone can help me with:

(1) I have TextBox controls on a form bound to Date fields
in a DataSet. Works great, except that when the TextBox
fields lose focus, when their Text paramter is a Date, the
DataSet (or something) appends the time to it. IOW, I
enter "1/7/2004", move to the next input field, and the
value magically changes itself to "1/7/2004 12:00:00 AM".

(2) I want to use an OleDbParamter to use a SQL "IN"
clause. In other words, sometimes I want to limit the
records on my form to certain Ids, but I want the default
to be all records in the table. The DataAdapter's
SelectCommand is set to "SELECT Id, FirstName FROM
Table". I want to be able to change this to "SELECT Id,
FirstName FROM Table WHERE Id IN (1, 4, 5)" (or
whatever). How can I do this?

Please help.
 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      7th Jan 2004
"James" <(E-Mail Removed)> schrieb
> So far, is basically dispise ADO.NET & VB.NET. Here's why:
>
> Too many confusing ways to do simple things. Here are two
> examples that maybe someone can help me with:
>
> (1) I have TextBox controls on a form bound to Date fields
> in a DataSet. Works great, except that when the TextBox
> fields lose focus, when their Text paramter is a Date, the
> DataSet (or something) appends the time to it. IOW, I
> enter "1/7/2004", move to the next input field, and the
> value magically changes itself to "1/7/2004 12:00:00 AM".


I haven't used databinding but I think you can handle the
System.Windows.Forms.Binding.Format event to get the right formatting.

> (2) I want to use an OleDbParamter to use a SQL "IN"
> clause. In other words, sometimes I want to limit the
> records on my form to certain Ids, but I want the default
> to be all records in the table. The DataAdapter's
> SelectCommand is set to "SELECT Id, FirstName FROM
> Table". I want to be able to change this to "SELECT Id,
> FirstName FROM Table WHERE Id IN (1, 4, 5)" (or
> whatever). How can I do this?


I don't know if this is the exact syntax (because it's a question for
micrsoft.public.dotnet.framework.adonet):

SELECT Id, FirstName FROM Table WHERE Id IN (@id1, @id2, @id3)

If the number of parameters varies, you have to build the select at runtime
instead of using parameters.

Or without parameters: "...IN (Select Id from temptable)". Table 'temptable'
must be filled before. This is usually only used whenever there can be a
large number of IDs.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      8th Jan 2004
James,
> (1) I have TextBox controls on a form bound to Date fields
> in a DataSet. Works great, except that when the TextBox

This is a side effect of having a single type that holds both Times & Dates.

As Armin suggested, I would look at the Format event to control this.

> (2) I want to use an OleDbParamter to use a SQL "IN"
> clause. In other words, sometimes I want to limit the

I would define two data adapters. One that does all and one that limits.
Alternatively I would define a single stored procedure that was able to do
either, based on its input parameters.

If you don't have it, I would recommend David Sceppa's book "Microsoft
ADO.NET - Core Reference" from MS Press, it is a very good tutorial on using
ADO.NET and also a good desk reference once you know ADO.NET.

Hope this helps
Jay


"James" <(E-Mail Removed)> wrote in message
news:0bb001c3d56d$8ef3f4d0$(E-Mail Removed)...
> So far, is basically dispise ADO.NET & VB.NET. Here's why:
>
> Too many confusing ways to do simple things. Here are two
> examples that maybe someone can help me with:
>
> (1) I have TextBox controls on a form bound to Date fields
> in a DataSet. Works great, except that when the TextBox
> fields lose focus, when their Text paramter is a Date, the
> DataSet (or something) appends the time to it. IOW, I
> enter "1/7/2004", move to the next input field, and the
> value magically changes itself to "1/7/2004 12:00:00 AM".
>
> (2) I want to use an OleDbParamter to use a SQL "IN"
> clause. In other words, sometimes I want to limit the
> records on my form to certain Ids, but I want the default
> to be all records in the table. The DataAdapter's
> SelectCommand is set to "SELECT Id, FirstName FROM
> Table". I want to be able to change this to "SELECT Id,
> FirstName FROM Table WHERE Id IN (1, 4, 5)" (or
> whatever). How can I do this?
>
> Please help.



 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      8th Jan 2004
Hi James,

Dates are no simple things in Dotnet.

If you write 1/7/2004 it is for me the first day of july in the year 2004.

While for some others it is the seventh day of january also in 2004

In the EU we use mostly a 24hours clock when official writing it

My 2Eurocents

Cor
>
> Too many confusing ways to do simple things. Here are two
> examples that maybe someone can help me with:



 
Reply With Quote
 
James
Guest
Posts: n/a
 
      8th Jan 2004
Thanks, I'll try the Binding.Format thing.

About the parameters, though, if I understand you
correctly, there's no way to change the SELECT statement
on an existing DataSet, is that right? If so, this is far
from an improvement over ADODB, don't you think?


>-----Original Message-----
>"James" <(E-Mail Removed)>

schrieb
>> So far, is basically dispise ADO.NET & VB.NET. Here's

why:
>>
>> Too many confusing ways to do simple things. Here are

two
>> examples that maybe someone can help me with:
>>
>> (1) I have TextBox controls on a form bound to Date

fields
>> in a DataSet. Works great, except that when the TextBox
>> fields lose focus, when their Text paramter is a Date,

the
>> DataSet (or something) appends the time to it. IOW, I
>> enter "1/7/2004", move to the next input field, and the
>> value magically changes itself to "1/7/2004 12:00:00

AM".
>
>I haven't used databinding but I think you can handle the
>System.Windows.Forms.Binding.Format event to get the

right formatting.
>
>> (2) I want to use an OleDbParamter to use a SQL "IN"
>> clause. In other words, sometimes I want to limit the
>> records on my form to certain Ids, but I want the

default
>> to be all records in the table. The DataAdapter's
>> SelectCommand is set to "SELECT Id, FirstName FROM
>> Table". I want to be able to change this to "SELECT Id,
>> FirstName FROM Table WHERE Id IN (1, 4, 5)" (or
>> whatever). How can I do this?

>
>I don't know if this is the exact syntax (because it's a

question for
>micrsoft.public.dotnet.framework.adonet):
>
>SELECT Id, FirstName FROM Table WHERE Id IN (@id1, @id2,

@id3)
>
>If the number of parameters varies, you have to build the

select at runtime
>instead of using parameters.
>
>Or without parameters: "...IN (Select Id from

temptable)". Table 'temptable'
>must be filled before. This is usually only used whenever

there can be a
>large number of IDs.
>
>--
>Armin
>
>http://www.plig.net/nnq/nquote.html
>http://www.netmeister.org/news/learn2quote.html
>
>.
>

 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      8th Jan 2004
"James" <(E-Mail Removed)> schrieb
> Thanks, I'll try the Binding.Format thing.
>
> About the parameters, though, if I understand you
> correctly, there's no way to change the SELECT statement
> on an existing DataSet, is that right?


You mean on an existing OleDBCommand? Or you wanna execute an SQL against a
Dataset?

> If so, this is far
> from an improvement over ADODB, don't you think?


Well, in ADODB, you had no parameters at all. Now you can use them in most
cases, but as you saw not in all cases. If you wanna discuss it, the group
microsoft.public.dotnet.framework.adonet is the better place.


--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

 
Reply With Quote
 
James
Guest
Posts: n/a
 
      8th Jan 2004
FWIW, I found/figured out how to do this:

---------------START CODE SAMPLE----------------
strSQL = "SELECT * FROM TableName WHERE Id IN (1, 4, 7)"
Me.dsDataSetName.Clear()
Me.dptAdapterName.SelectCommand = _
New System.Data.OleDb.OleDbCommand(strSQL)
Me.dptAdapterName.SelectCommand.Connection =
conConnectionName
Me.dptAdapterName.Fill(Me.dsDataSetName, "TableName")
---------------END CODE SAMPLE----------------

Works great. Thanks for your responses.


>-----Original Message-----
>"James" <(E-Mail Removed)>

schrieb
>> Thanks, I'll try the Binding.Format thing.
>>
>> About the parameters, though, if I understand you
>> correctly, there's no way to change the SELECT statement
>> on an existing DataSet, is that right?

>
>You mean on an existing OleDBCommand? Or you wanna

execute an SQL against a
>Dataset?
>
>> If so, this is far
>> from an improvement over ADODB, don't you think?

>
>Well, in ADODB, you had no parameters at all. Now you can

use them in most
>cases, but as you saw not in all cases. If you wanna

discuss it, the group
>microsoft.public.dotnet.framework.adonet is the better

place.
>
>
>--
>Armin
>
>http://www.plig.net/nnq/nquote.html
>http://www.netmeister.org/news/learn2quote.html
>
>.
>

 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      9th Jan 2004
James,
A DataSet does not have a select statement. Only Commands have select
statements. A DataAdapter can have a SelectCommand, plus an Update, Delete &
Create command.

You can change the text of the SelectCommand associated with a DataAdapter &
then repopulate the Parameters. However I have to seriously ask why?

It seems to be more work, when IMHO its easier to have two DataAdapters, one
with the full select & the Update, Delete & Create commands. Plus a second
one with just the partial select. Actually you could have 3 DataAdapters.
One with full select, one with partial select, then one for Update, Delete &
Create.

Remember the DataAdapter you use to Fill a DataSet does not need to be the
DataAdapter you use to Update a DataSet.

Hope this helps
Jay

"James" <(E-Mail Removed)> wrote in message
news:00e301c3d60a$2f4194f0$(E-Mail Removed)...
> Thanks, I'll try the Binding.Format thing.
>
> About the parameters, though, if I understand you
> correctly, there's no way to change the SELECT statement
> on an existing DataSet, is that right? If so, this is far
> from an improvement over ADODB, don't you think?
>
>
> >-----Original Message-----
> >"James" <(E-Mail Removed)>

> schrieb
> >> So far, is basically dispise ADO.NET & VB.NET. Here's

> why:
> >>
> >> Too many confusing ways to do simple things. Here are

> two
> >> examples that maybe someone can help me with:
> >>
> >> (1) I have TextBox controls on a form bound to Date

> fields
> >> in a DataSet. Works great, except that when the TextBox
> >> fields lose focus, when their Text paramter is a Date,

> the
> >> DataSet (or something) appends the time to it. IOW, I
> >> enter "1/7/2004", move to the next input field, and the
> >> value magically changes itself to "1/7/2004 12:00:00

> AM".
> >
> >I haven't used databinding but I think you can handle the
> >System.Windows.Forms.Binding.Format event to get the

> right formatting.
> >
> >> (2) I want to use an OleDbParamter to use a SQL "IN"
> >> clause. In other words, sometimes I want to limit the
> >> records on my form to certain Ids, but I want the

> default
> >> to be all records in the table. The DataAdapter's
> >> SelectCommand is set to "SELECT Id, FirstName FROM
> >> Table". I want to be able to change this to "SELECT Id,
> >> FirstName FROM Table WHERE Id IN (1, 4, 5)" (or
> >> whatever). How can I do this?

> >
> >I don't know if this is the exact syntax (because it's a

> question for
> >micrsoft.public.dotnet.framework.adonet):
> >
> >SELECT Id, FirstName FROM Table WHERE Id IN (@id1, @id2,

> @id3)
> >
> >If the number of parameters varies, you have to build the

> select at runtime
> >instead of using parameters.
> >
> >Or without parameters: "...IN (Select Id from

> temptable)". Table 'temptable'
> >must be filled before. This is usually only used whenever

> there can be a
> >large number of IDs.
> >
> >--
> >Armin
> >
> >http://www.plig.net/nnq/nquote.html
> >http://www.netmeister.org/news/learn2quote.html
> >
> >.
> >



 
Reply With Quote
 
James
Guest
Posts: n/a
 
      9th Jan 2004
I'm doing this because I have form controls bound to it.
If I had more than one DataAdapter, I'd hve to reboind all
my controls every time I wanted to change the underlying
dataset. That would be insane.

I DID figure out how to do this, BTW. I posted it
yesterday, but here it is again (it's a pretty useful
thing to know how to do:

---------------START CODE SAMPLE----------------
strSQL = "SELECT * FROM TableName WHERE Id IN (1, 4, 7)"
Me.dsDataSetName.Clear()
Me.dptAdapterName.SelectCommand = _
New System.Data.OleDb.OleDbCommand(strSQL)
Me.dptAdapterName.SelectCommand.Connection = _
conConnectionName
Me.dptAdapterName.Fill(Me.dsDataSetName, "TableName")
---------------END CODE SAMPLE----------------

>-----Original Message-----
>James,
>A DataSet does not have a select statement. Only Commands

have select
>statements. A DataAdapter can have a SelectCommand, plus

an Update, Delete &
>Create command.
>
>You can change the text of the SelectCommand associated

with a DataAdapter &
>then repopulate the Parameters. However I have to

seriously ask why?
>
>It seems to be more work, when IMHO its easier to have

two DataAdapters, one
>with the full select & the Update, Delete & Create

commands. Plus a second
>one with just the partial select. Actually you could have

3 DataAdapters.
>One with full select, one with partial select, then one

for Update, Delete &
>Create.
>
>Remember the DataAdapter you use to Fill a DataSet does

not need to be the
>DataAdapter you use to Update a DataSet.
>
>Hope this helps
>Jay
>
>"James" <(E-Mail Removed)>

wrote in message
>news:00e301c3d60a$2f4194f0$(E-Mail Removed)...
>> Thanks, I'll try the Binding.Format thing.
>>
>> About the parameters, though, if I understand you
>> correctly, there's no way to change the SELECT statement
>> on an existing DataSet, is that right? If so, this is

far
>> from an improvement over ADODB, don't you think?
>>
>>
>> >-----Original Message-----
>> >"James" <jrbradyNOSPAM@NOSPAMsenior-

direct.comNODAMNSPAM>
>> schrieb
>> >> So far, is basically dispise ADO.NET & VB.NET.

Here's
>> why:
>> >>
>> >> Too many confusing ways to do simple things. Here

are
>> two
>> >> examples that maybe someone can help me with:
>> >>
>> >> (1) I have TextBox controls on a form bound to Date

>> fields
>> >> in a DataSet. Works great, except that when the

TextBox
>> >> fields lose focus, when their Text paramter is a

Date,
>> the
>> >> DataSet (or something) appends the time to it. IOW,

I
>> >> enter "1/7/2004", move to the next input field, and

the
>> >> value magically changes itself to "1/7/2004 12:00:00

>> AM".
>> >
>> >I haven't used databinding but I think you can handle

the
>> >System.Windows.Forms.Binding.Format event to get the

>> right formatting.
>> >
>> >> (2) I want to use an OleDbParamter to use a SQL "IN"
>> >> clause. In other words, sometimes I want to limit

the
>> >> records on my form to certain Ids, but I want the

>> default
>> >> to be all records in the table. The DataAdapter's
>> >> SelectCommand is set to "SELECT Id, FirstName FROM
>> >> Table". I want to be able to change this to "SELECT

Id,
>> >> FirstName FROM Table WHERE Id IN (1, 4, 5)" (or
>> >> whatever). How can I do this?
>> >
>> >I don't know if this is the exact syntax (because it's

a
>> question for
>> >micrsoft.public.dotnet.framework.adonet):
>> >
>> >SELECT Id, FirstName FROM Table WHERE Id IN (@id1,

@id2,
>> @id3)
>> >
>> >If the number of parameters varies, you have to build

the
>> select at runtime
>> >instead of using parameters.
>> >
>> >Or without parameters: "...IN (Select Id from

>> temptable)". Table 'temptable'
>> >must be filled before. This is usually only used

whenever
>> there can be a
>> >large number of IDs.
>> >
>> >--
>> >Armin
>> >
>> >http://www.plig.net/nnq/nquote.html
>> >http://www.netmeister.org/news/learn2quote.html
>> >
>> >.
>> >

>
>
>.
>

 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      9th Jan 2004
James,
Are these custom controls?

As all the normal form controls bind to a DataView (over a DataTable,
contained in a DataSet). You do not bind to a DataAdapter, you only use the
DataAdapter to fill the DataSet, You can fill a single DataSet from any
number of DataAdapters without rebinding! You can fill a single DataTable
from any number of DataAdapters again without rebinding! As long as the
various DataAdapters have a select command that return compatible columns.

I did not say change the DataSet, I told you to use a different DataAdapter
to fill the DataSet!

I saw your post yesterday, I will continue to recommend multiple
DataAdapters! As IMHO it is the "cleaner" solution. However if your solution
works for you, go for it! I'm sure there is at least a third viable method
you can use to accomplish the same thing!

In case you don't have it, you may want to pick up David Sceppa's book
"Microsoft ADO.NET - Core Reference" from MS Press. It fully explains the
difference between binding to a DataSet and using different DataAdapters to
populate the DataSet! Also David's book is a good tutorial on ADO.NET, plus
a good desk reference once you know ADO.NET.

I hope you realize when I say use two DataAdapters, I mean populate the same
DataTable with two different DataAdapters, do not use two DataAdapters to
populate two DataTables! Otherwise as you say "that would be insane" ;-)

Hope this helps
Jay

"James" <(E-Mail Removed)> wrote in message
news:022e01c3d6d5$8e2085a0$(E-Mail Removed)...
> I'm doing this because I have form controls bound to it.
> If I had more than one DataAdapter, I'd hve to reboind all
> my controls every time I wanted to change the underlying
> dataset. That would be insane.
>
> I DID figure out how to do this, BTW. I posted it
> yesterday, but here it is again (it's a pretty useful
> thing to know how to do:
>
> ---------------START CODE SAMPLE----------------
> strSQL = "SELECT * FROM TableName WHERE Id IN (1, 4, 7)"
> Me.dsDataSetName.Clear()
> Me.dptAdapterName.SelectCommand = _
> New System.Data.OleDb.OleDbCommand(strSQL)
> Me.dptAdapterName.SelectCommand.Connection = _
> conConnectionName
> Me.dptAdapterName.Fill(Me.dsDataSetName, "TableName")
> ---------------END CODE SAMPLE----------------
>
> >-----Original Message-----
> >James,
> >A DataSet does not have a select statement. Only Commands

> have select
> >statements. A DataAdapter can have a SelectCommand, plus

> an Update, Delete &
> >Create command.
> >
> >You can change the text of the SelectCommand associated

> with a DataAdapter &
> >then repopulate the Parameters. However I have to

> seriously ask why?
> >
> >It seems to be more work, when IMHO its easier to have

> two DataAdapters, one
> >with the full select & the Update, Delete & Create

> commands. Plus a second
> >one with just the partial select. Actually you could have

> 3 DataAdapters.
> >One with full select, one with partial select, then one

> for Update, Delete &
> >Create.
> >
> >Remember the DataAdapter you use to Fill a DataSet does

> not need to be the
> >DataAdapter you use to Update a DataSet.
> >
> >Hope this helps
> >Jay
> >
> >"James" <(E-Mail Removed)>

> wrote in message
> >news:00e301c3d60a$2f4194f0$(E-Mail Removed)...
> >> Thanks, I'll try the Binding.Format thing.
> >>
> >> About the parameters, though, if I understand you
> >> correctly, there's no way to change the SELECT statement
> >> on an existing DataSet, is that right? If so, this is

> far
> >> from an improvement over ADODB, don't you think?
> >>
> >>
> >> >-----Original Message-----
> >> >"James" <jrbradyNOSPAM@NOSPAMsenior-

> direct.comNODAMNSPAM>
> >> schrieb
> >> >> So far, is basically dispise ADO.NET & VB.NET.

> Here's
> >> why:
> >> >>
> >> >> Too many confusing ways to do simple things. Here

> are
> >> two
> >> >> examples that maybe someone can help me with:
> >> >>
> >> >> (1) I have TextBox controls on a form bound to Date
> >> fields
> >> >> in a DataSet. Works great, except that when the

> TextBox
> >> >> fields lose focus, when their Text paramter is a

> Date,
> >> the
> >> >> DataSet (or something) appends the time to it. IOW,

> I
> >> >> enter "1/7/2004", move to the next input field, and

> the
> >> >> value magically changes itself to "1/7/2004 12:00:00
> >> AM".
> >> >
> >> >I haven't used databinding but I think you can handle

> the
> >> >System.Windows.Forms.Binding.Format event to get the
> >> right formatting.
> >> >
> >> >> (2) I want to use an OleDbParamter to use a SQL "IN"
> >> >> clause. In other words, sometimes I want to limit

> the
> >> >> records on my form to certain Ids, but I want the
> >> default
> >> >> to be all records in the table. The DataAdapter's
> >> >> SelectCommand is set to "SELECT Id, FirstName FROM
> >> >> Table". I want to be able to change this to "SELECT

> Id,
> >> >> FirstName FROM Table WHERE Id IN (1, 4, 5)" (or
> >> >> whatever). How can I do this?
> >> >
> >> >I don't know if this is the exact syntax (because it's

> a
> >> question for
> >> >micrsoft.public.dotnet.framework.adonet):
> >> >
> >> >SELECT Id, FirstName FROM Table WHERE Id IN (@id1,

> @id2,
> >> @id3)
> >> >
> >> >If the number of parameters varies, you have to build

> the
> >> select at runtime
> >> >instead of using parameters.
> >> >
> >> >Or without parameters: "...IN (Select Id from
> >> temptable)". Table 'temptable'
> >> >must be filled before. This is usually only used

> whenever
> >> there can be a
> >> >large number of IDs.
> >> >
> >> >--
> >> >Armin
> >> >
> >> >http://www.plig.net/nnq/nquote.html
> >> >http://www.netmeister.org/news/learn2quote.html
> >> >
> >> >.
> >> >

> >
> >
> >.
> >



 
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
IE confusion Mist Windows XP General 11 20th Sep 2008 06:16 PM
ASP.Net confusion between 1.1 and 2.0 Brent Microsoft ADO .NET 4 26th May 2006 09:40 PM
Re: Can someone end my confusion ? fredg Microsoft Access Reports 0 5th Aug 2004 11:46 PM
xp/98 confusion NY1 Windows XP Basics 4 20th Mar 2004 01:16 AM
Confusion about DDE Heidi Linda Windows XP Embedded 0 3rd Oct 2003 11:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:35 AM.