473,498 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

More than one parameter??

I am trying to display a bunch of rows from a database in a DataGrid, and I
want to sort them by year. I decided to use the "WHERE (yearID BETWEEN ? And
?)" query in the OleDbDataAdapter to get only the rows from the database
that were between two different years (which are specified at run-time).

The problem I am having is with this line:

OleDbDataAdapter4.SelectCommand.Parameters("yearID ").Value = [What should I
put here?]

Since I need two distinct numbers to use as parameters, how can I assign
them both to "yearID"? Thanks in advance.

Jay
Nov 20 '05 #1
9 1146
if you need two numbers why not use use two parameters and add more then one
parametere to the parameteres collection? I've never seen it done the way
you want to do it ever
"jy836" <mo***@nospam.com> wrote in message
news:7FFQb.116014$nt4.475219@attbi_s51...
I am trying to display a bunch of rows from a database in a DataGrid, and I want to sort them by year. I decided to use the "WHERE (yearID BETWEEN ? And ?)" query in the OleDbDataAdapter to get only the rows from the database
that were between two different years (which are specified at run-time).

The problem I am having is with this line:

OleDbDataAdapter4.SelectCommand.Parameters("yearID ").Value = [What should I put here?]

Since I need two distinct numbers to use as parameters, how can I assign
them both to "yearID"? Thanks in advance.

Jay

Nov 20 '05 #2
"Brian Henry" <brianiup[remove-me]@adelphia.net> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
if you need two numbers why not use use two parameters and add more then one parametere to the parameteres collection? I've never seen it done the way
you want to do it ever


I'm not sure I understand. It's not that I need two numbers from the
database; I'm trying to display only the records from a certain span of
years. So I used the "BETWEEN" statement in my parameter for the "yearID"
field, but I don't know how to assign two numbers to one parameter.
Nov 20 '05 #3
with SQL server you can use named parameters like @startdate @enddate... I
don't remember if you can force OLEDB to do that, but you may want to try
named parameters like that, then assign a value to each parametere name
"jy836" <mo***@nospam.com> wrote in message
news:oOGQb.116376$nt4.477885@attbi_s51...
"Brian Henry" <brianiup[remove-me]@adelphia.net> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
if you need two numbers why not use use two parameters and add more then

one
parametere to the parameteres collection? I've never seen it done the way you want to do it ever


I'm not sure I understand. It's not that I need two numbers from the
database; I'm trying to display only the records from a certain span of
years. So I used the "BETWEEN" statement in my parameter for the "yearID"
field, but I don't know how to assign two numbers to one parameter.

Nov 20 '05 #4
"Brian Henry" <brianiup[remove-me]@adelphia.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
with SQL server you can use named parameters like @startdate @enddate... I
don't remember if you can force OLEDB to do that, but you may want to try
named parameters like that, then assign a value to each parametere name


Hmm...sorry, I'm very new to VB .NET. What exactly are "named" versus
"unnamed" parameters? And how would I go about using them? Thanks a bunch!
You guys have been a great help... :-D

Jay
Nov 20 '05 #5
named parameters can have multiple values for the same column when checking
like what you are trying to do when unnamed is based on the column name it's
in refrence to
"jy836" <mo***@nospam.com> wrote in message
news:g0HQb.113838$sv6.589635@attbi_s52...
"Brian Henry" <brianiup[remove-me]@adelphia.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
with SQL server you can use named parameters like @startdate @enddate... I don't remember if you can force OLEDB to do that, but you may want to try named parameters like that, then assign a value to each parametere name


Hmm...sorry, I'm very new to VB .NET. What exactly are "named" versus
"unnamed" parameters? And how would I go about using them? Thanks a bunch!
You guys have been a great help... :-D

Jay

Nov 20 '05 #6
named parameters you can do stuff like this

SELECT * FROM TABLE WHERE A = @value1 and A < @value2 or A > @value3

each parameter @value1 @value2 @value3 can have diffrent values.. you would
make a new parametere in the parameteres collection for the sql command like
this

cmdSQLSelect.parameters.add("@value1",data.sqldata type.int).value = 12
cmdSQLSelect.parameters.add("@value2",data.sqldata type.int).value = 46
cmdSQLSelect.parameters.add("@value3",data.sqldata type.int).value = 1
"jy836" <mo***@nospam.com> wrote in message
news:g0HQb.113838$sv6.589635@attbi_s52...
"Brian Henry" <brianiup[remove-me]@adelphia.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
with SQL server you can use named parameters like @startdate @enddate... I don't remember if you can force OLEDB to do that, but you may want to try named parameters like that, then assign a value to each parametere name


Hmm...sorry, I'm very new to VB .NET. What exactly are "named" versus
"unnamed" parameters? And how would I go about using them? Thanks a bunch!
You guys have been a great help... :-D

Jay

Nov 20 '05 #7
Jay,
In addition to Brian's comments.

If you want to select records for a given year you should not be using
BETWEEN, I would use equals "=" instead.

However if you want to select records for a span of years, including
possible one year, then you should use between.

' Where (YearID = ?)
' only supports selecting one year.
OleDbDataAdapter4.SelectCommand.Parameters("P1").V alue = 2004

' Where (YearID Between ? and ?)
' if you want to select two years you would use: OleDbDataAdapter4.SelectCommand.Parameters("P1").V alue = 2003
OleDbDataAdapter4.SelectCommand.Parameters("P2").V alue = 2004
' if you want to select one year (with between) you would use: OleDbDataAdapter4.SelectCommand.Parameters("P1").V alue = 2004
OleDbDataAdapter4.SelectCommand.Parameters("P2").V alue = 2004
Where YearID happens to be a field on the table you are running the select
against, while P1 & P2 are parameters to the SelectCommand (the names used
in the Parameters collection). Note, P1 could literally be the string
yearID, however this is not required. Instead of using the text name you can
use ordinal position (0, 1, 2...)

If you do not have it, I would strongly recommend you purchase David
Sceppa's book "Microsoft ADO.NET - Core Reference" from MS Press. It is both
a good tutorial on ADO.NET as well as a good desk reference once you know
ADO.NET.

Hope this helps
Jay


"jy836" <mo***@nospam.com> wrote in message
news:7FFQb.116014$nt4.475219@attbi_s51... I am trying to display a bunch of rows from a database in a DataGrid, and I want to sort them by year. I decided to use the "WHERE (yearID BETWEEN ? And ?)" query in the OleDbDataAdapter to get only the rows from the database
that were between two different years (which are specified at run-time).

The problem I am having is with this line:

OleDbDataAdapter4.SelectCommand.Parameters("yearID ").Value = [What should I put here?]

Since I need two distinct numbers to use as parameters, how can I assign
them both to "yearID"? Thanks in advance.

Jay

Nov 20 '05 #8
Whew! I finally got it to work. Much thanks to Brian Henry and Jay B. Harlow
for your help! I'd still be trying to figure out how to make it work without
your help....thanks again! :-)

Jay

P.S. I'm sure I'll be back for more questions soon! :-)
Nov 20 '05 #9
On Sun, 25 Jan 2004 20:42:46 GMT, jy836 wrote:
I'd still be trying to figure out how to make it work without your help


That's why they get paid the big bucks!

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2129
by: Tony Johansson | last post by:
Hello Experts! I have the following Array template class see below. I execute these three statements statement 1: Array<int> x(5); statement 2: cin >>x; statement 3: Array<int>::element_type ...
11
2557
by: Micha | last post by:
Hello there, I think I've run into some classic c++ pitfall and maybe some of you guys can help me out. For my project I will need to use matrices and vectors and so I decided to implement them...
2
1899
by: Bibi | last post by:
Hi, i have a SqlWindows Program which made a connection to a MS Access Database about ODBC. I can get all datas with a select about one table. But when i made a select with more than one table,...
5
3736
by: Fresh Air Rider | last post by:
Hello Could anyone please explain how I can pass more than one arguement/parameter value to a function using <asp:linkbutton> or is this a major shortfall of the language ? Consider the...
0
3618
by: Dean Sabella | last post by:
Hi, I was trying to run a crystal report in the .net sample application given at: http://support.crystaldecisions.com/communityCS/FilesAndUpdates/ cppnet_win_subreport_basic.exe.asp (I've...
3
8812
by: Brian Foree | last post by:
I am developing an ASP.NET application that uses Access 2000 as its backend, and have just started getting the following error on 2 ASP.NET pages that had been working until late last week (and I...
4
1637
by: trond | last post by:
Hello all, Before I start I'd like to point out that I am a complete novice when it comes to asp.net - My background is in network and operating systems, and although I have been doing a bit of...
2
2608
by: Hexman | last post by:
Hello All, Well I'm stumped once more. Need some help. Writing a simple select and update program using VB.Net 2005 and an Access DB. I'm using parameters in my update statement and when trying...
0
1293
by: abednegoo | last post by:
Hi All, I tried to find the solution for my problem, but i couldn't find it. If my problem is already solved somewhere, please provide me the link... I'm not a developer myself, but the...
151
7906
by: istillshine | last post by:
There are many languages around: C++, JAVA, PASCAL, and so on. I tried to learn C++ and JAVA, but ended up criticizing them. Is it because C was my first programming language? I like C...
0
7126
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7005
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4916
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4595
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
293
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.