473,414 Members | 1,964 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

parameter passing asp.net vb

hi,

I'm a relative newbie to .net but have been an asp developer for a few
years. I'm starting the slow and somehwat painful process of learning
how to do everything I used to do in asp in .net.

i'm using visual studio and am simply trying to do the following:

Pass a value into a stored procedure or a sql query which has been is
passed via a querystring.

I've achieved this by setting the value of the parameter in the
desinger generated code but I would like to be able to handle this in
the page_load. I'd like to check for the existence of a paramater and
pass this value to the query.

I'm sure it's really easy, it certainly is in classic asp but i'm
really struggling with this one.

Anyone help?
Nov 19 '05 #1
6 1250
page_load.....

if(Request.QueryString("val") != null)
{
string myVal = Request.QueryStirng("val");
...your other stuff....
}

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Ben Barnes" <be**********@hotmail.com> wrote in message
news:4a*************************@posting.google.co m...
hi,

I'm a relative newbie to .net but have been an asp developer for a few
years. I'm starting the slow and somehwat painful process of learning
how to do everything I used to do in asp in .net.

i'm using visual studio and am simply trying to do the following:

Pass a value into a stored procedure or a sql query which has been is
passed via a querystring.

I've achieved this by setting the value of the parameter in the
desinger generated code but I would like to be able to handle this in
the page_load. I'd like to check for the existence of a paramater and
pass this value to the query.

I'm sure it's really easy, it certainly is in classic asp but i'm
really struggling with this one.

Anyone help?

Nov 19 '05 #2
Hi Curt,

Thanks. the above I can handle but it is passing the value back into
the query to be the parameter that I'm struggling with.

So, it's a case of putting myVal back as the value of
Me.SqlCommand1.Parameters.Add

Nov 19 '05 #3
Ben,
It isn't too complicated, but it can certainly be confusing at first.
Personally I'm not the biggest fan of design time stuff, I realize it's much
quicker and simpler, but if you're like me, you like having a fine grain
control. Additionally, you learn a lot more by doing it yourself.

Having said that, I'm not 100% sure what step you are having a hard time
with. Is it simply getting a value from the querystring? or assigning it as
a parameter? Without knowing what you have, I'll show you a basic way of
doing the entire thing:

(code not compiled, typing it off the top of my head)

Sub Page_Load
dim id as integer = 0
if Request.QueryString("userId") is nothing then
id = -1 'some default value
else
id = Convert.ToInt32(Request.QueryString("userId")) 'could throw an
exception if it isn't a valid it, so you might wanna try/catch this
end if

dim connection as new SqlConnection(CONNECTION_STRING)
dim command as new SqlCommand(connection, "STORED_PROCEDURE_NAME")
command.commandType = commandType.StoredProcedure
command.Parameters.Add("@UserId", SqlDbType.Int).Value = id 'here's where
you assign the variable to the sproc

dim ds as new DataSet
dim da as new SqlDataAdapter(command)
try
connection.Open()
da.Fill(ds)
finally
connection.dispose()
command.dispose()
da.dispose()
end try
you now have a DataSet (ds) with the data..

The above code should be moved into a utility function, which returns a
dataset, so that you can reuse it, but other than that, all should be good.

lemme know if anything specific irkes you.

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Ben Barnes" <be**********@hotmail.com> wrote in message
news:4a*************************@posting.google.co m...
hi,

I'm a relative newbie to .net but have been an asp developer for a few
years. I'm starting the slow and somehwat painful process of learning
how to do everything I used to do in asp in .net.

i'm using visual studio and am simply trying to do the following:

Pass a value into a stored procedure or a sql query which has been is
passed via a querystring.

I've achieved this by setting the value of the parameter in the
desinger generated code but I would like to be able to handle this in
the page_load. I'd like to check for the existence of a paramater and
pass this value to the query.

I'm sure it's really easy, it certainly is in classic asp but i'm
really struggling with this one.

Anyone help?

Nov 19 '05 #4
Hi Karl,

Spot on, that looks like it will do the trick! thanks

The thing is I'm doing this through Visual Studio and am draggin the
tables onto the designer surface and hooking things up that way.
Getting data out is fine and foring a parameter is also ok but getting
the value of the parameter to be passedin at deisgn time is a touch
more tricky.

Thanks your help, I'll give it a go, but it looks like it will do the
job perfectly. Thanks for taking the time to reply..

Nov 19 '05 #5
..Add("@paramName",myVal);

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
<be**********@hotmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Hi Curt,

Thanks. the above I can handle but it is passing the value back into
the query to be the parameter that I'm struggling with.

So, it's a case of putting myVal back as the value of
Me.SqlCommand1.Parameters.Add

Nov 19 '05 #6
oops... typo... see what Karl wrote :}

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
<be**********@hotmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Hi Curt,

Thanks. the above I can handle but it is passing the value back into
the query to be the parameter that I'm struggling with.

So, it's a case of putting myVal back as the value of
Me.SqlCommand1.Parameters.Add

Nov 19 '05 #7

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

Similar topics

3
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can...
6
by: Brian Ross | last post by:
Hi, I am trying to do something similar to the following: int Func1(int x, int y); double Func2(double x, double y); template <typename FuncT> // <- What would go here class CObjectT {
4
by: Ron Rohrssen | last post by:
I want to show a dialog and when the form (dialog) is closed, return to the calling form. The calling form should then be able to pass the child form to another object with the form as a...
6
by: wiredless | last post by:
What is the advantage of passing an interface type? according to UML (visio) when i reverse engineer existing code to a UML diagram I get the error "UMLE00046: sample : - An interface cannot...
21
by: vmsgman | last post by:
Here is a code sample ... int blah = ReadFile( defArray, defFileName, w, h); // Read File Contents into memory array and return for processing public int ReadFile( ref ushort nArray, string...
20
by: Brien King | last post by:
If I have a parameter that has an Object type (as opposed to something like a string), can I make that parameter a CONST? Right now, if you pass an object into a sub/function, that sub/function...
4
by: Ranginald | last post by:
Hi, I'm having trouble passing a parameter from my default.aspx page to my default2.aspx page. I have values from a query in a list box and the goal is to pass the "catID" from default.aspx...
8
by: =?Utf-8?B?UmF2aQ==?= | last post by:
Hi, I'm trying to pass values of different data-types to a web-service. I thought it would be easier to box these values and pass them as a System.object parameter, like public void...
16
by: Theo R. | last post by:
Hi all, Does the C99 Standard explicitly mention the need for a stack for passing arguments or Is this platform specific? As an example, the ARM9 processor recommends Core Registers R0-R3 be...
4
by: =?Utf-8?B?QmlsbEF0V29yaw==?= | last post by:
Hi, We recently converted a 1.1 project to 2.0 and this included a webservice which accepted XML for one of the parameters. Since converting to 2.0 I am getting the following message: --- A...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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
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...

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.