473,831 Members | 2,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help me on this with SQLPARAMETERS

I have a parameter below and i'm passing the value via Store procedure
Cmd.Parameters. Add(New SqlParameter("@ ProductID", SqlDbType.Int, 1)).Value =
104
But as you can see the value "104" is hard coded..
My problem is on the same page i have a CHECKBOXLIST which is DAtabinded
and the DataValuefield i binded it to increments 1,2,3... which is p_id(I'm
doing that becos i need to pass those values)
My table looks like this :-
p_id ProductId chkText
1 104 Bank
2 104 Phone

My problem is i want to retrun the value 104 and not hard code it
there.Would it possibe to query the table like using:-
select TOP 1 productid from ProductFeatures which just returns value "104"
and append it to the Sqlparameters above.
any ideas?



Nov 19 '05 #1
5 1480
Why not user a DropDownList, or a RadioButton list to stored your Product
ID's.

The user can select that and you can build your Parameter based on that

so:

DropDownList (this would be loaded dynamicly setting the value to your
ProductID)

<asp:DropDownLi st id="dd" runat="server">
<asp:ListItem value="104">Ban k</asp:ListItem>
<asp:ListItem value="104">Pho ne</asp:ListItem>
</asp:DropDownLis t>

Parameter:

Cmd.Parameters. Add(New SqlParameter("@ ProductID", SqlDbType.Int,
1)).Value = dd.SelectedValu e;
HTH

"Patrick.O. Ige" <na********@hot mail.com> wrote in message
news:e2******** ********@TK2MSF TNGP09.phx.gbl. ..
I have a parameter below and i'm passing the value via Store procedure
Cmd.Parameters. Add(New SqlParameter("@ ProductID", SqlDbType.Int, 1)).Value
=
104
But as you can see the value "104" is hard coded..
My problem is on the same page i have a CHECKBOXLIST which is DAtabinded
and the DataValuefield i binded it to increments 1,2,3... which is
p_id(I'm
doing that becos i need to pass those values)
My table looks like this :-
p_id ProductId chkText
1 104 Bank
2 104 Phone

My problem is i want to retrun the value 104 and not hard code it
there.Would it possibe to query the table like using:-
select TOP 1 productid from ProductFeatures which just returns value "104"
and append it to the Sqlparameters above.
any ideas?


Nov 19 '05 #2
Grant thanks for the idea..
But i don't want it this way:-
<asp:DropDownLi st id="dd" runat="server">
<asp:ListItem value="104">Ban k</asp:ListItem>
<asp:ListItem value="104">Pho ne</asp:ListItem>
</asp:DropDownLis t>

I want it dynamic so i have Databinded a DropDownlist.
But something seems funny here if i use
tha above it works

and if i don't databind it works
But if i databind it and then set :- Cmd.Parameters. Add(New
SqlParameter("@ ProductID", SqlDbType.Int,
1)).Value = dd.SelectedValu e;
it seems not to read the DropDwon selected value!!!

But i notice i can get the Selected value on page_load
And again if i view the source i can see the values are set well..

I have also set visible to FALSE since i don't want to make the
DropDownList visiblae but just to use it to set the value..

in page_load i have
If Not Page.IsPostBack Then

DropDown_Featur es()'dropdownli st
GetValue()'drop downlist where i get the
dd.SelectedItem .Value
'Response.Write ("" & dd.SelectedItem .Value & "")
End If

But in my sub DropDown_Featur es()if i try and set
Cmd.Parameters. Add(New SqlParameter("@ ProductID", SqlDbType.Int,
1)).Value = dd.SelectedValu e;

I get an error "Input string was not in a correct format.
"
Any ideas?


*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #3
Ok, i'm officially confused.

Why would you want to set the DropDownList's visibility to FALSE.
If its not something the user is selecting, then it should be something that
worked out in the code.
Either stored when the page loads, and called when you need it.
Or, worked out when you need it based on whatever criteria you've used.

Is this a case where it will alway be one value (i don't mean like 104, but
both bank and phone have 104)
So is it just a Product ID that can be stored as one value for the given
page.

Like:
A page that displays a product that a user can update and you are trying
to store the product id to do the update.
What i'm getting at, is if the dropdownlist is not visible, the user is not
selecting a value from it, so how do you know which item from that list to
use.
Or better yet, if you do know which item to use, why do you need a
dropdownlist of options, when you infact only need one option?
"Patrick Olurotimi Ige" <na********@hot mail.com> wrote in message
news:ee******** ******@TK2MSFTN GP12.phx.gbl...
Grant thanks for the idea..
But i don't want it this way:-
<asp:DropDownLi st id="dd" runat="server">
<asp:ListItem value="104">Ban k</asp:ListItem>
<asp:ListItem value="104">Pho ne</asp:ListItem>
</asp:DropDownLis t>

I want it dynamic so i have Databinded a DropDownlist.
But something seems funny here if i use
tha above it works

and if i don't databind it works
But if i databind it and then set :- Cmd.Parameters. Add(New
SqlParameter("@ ProductID", SqlDbType.Int,
1)).Value = dd.SelectedValu e;
it seems not to read the DropDwon selected value!!!

But i notice i can get the Selected value on page_load
And again if i view the source i can see the values are set well..

I have also set visible to FALSE since i don't want to make the
DropDownList visiblae but just to use it to set the value..

in page_load i have
If Not Page.IsPostBack Then

DropDown_Featur es()'dropdownli st
GetValue()'drop downlist where i get the
dd.SelectedItem .Value
'Response.Write ("" & dd.SelectedItem .Value & "")
End If

But in my sub DropDown_Featur es()if i try and set
Cmd.Parameters. Add(New SqlParameter("@ ProductID", SqlDbType.Int,
1)).Value = dd.SelectedValu e;

I get an error "Input string was not in a correct format.
"
Any ideas?


*** Sent via Developersdex http://www.developersdex.com ***

Nov 19 '05 #4
Grant..
Thats very right that if the user doesn't select a DropDwonList i can't
get the selected value but if i set :-
dd.SelectedItem .Value of the DropDownList in Page_Load i can recieve the
value. But seeting it beyond page_load won't work..
Any other ideas how i can store the value and then use it later on?


*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #5
Yes!

either Session or ViewState it.

So when you page loads, and your have a value called MyValue of type Int;
In the Page_Load do: (in c#)
Session["MyValue"] = MyValue;
or
ViewState["MyValue"] = MyValue;

Then when you want to retrieve it:
MyValue = (int)Session["MyValue"];
or
MyValue = (int)ViewState["MyValue"];

"Patrick Olurotimi Ige" <na********@hot mail.com> wrote in message
news:OD******** ******@TK2MSFTN GP11.phx.gbl...
Grant..
Thats very right that if the user doesn't select a DropDwonList i can't
get the selected value but if i set :-
dd.SelectedItem .Value of the DropDownList in Page_Load i can recieve the
value. But seeting it beyond page_load won't work..
Any other ideas how i can store the value and then use it later on?


*** Sent via Developersdex http://www.developersdex.com ***

Nov 19 '05 #6

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

Similar topics

4
6295
by: Gav | last post by:
Hi All, Can somebody tell me the advantage of using SqlParameters over simple putting the paratmeters in the sql string: ie Getsomething(int nSomeNumber) { string sSqlStatement= "Select * From SomeTable Where index = " + nSomeNumber.ToString(); SqlCommand ....etc
0
1157
by: Rein | last post by:
Hi, I'm trying to call a stored procedure using SqlCommand and SqlParameters. My problem is this: I have a uint that is set to the value: 0xffff0000. When I try to assign it to a SqlParameter of type SqlDbType.Int and execute the stored procedure I get the following error: System.OverflowException: Value was either too large or too small for an Int64. This is probably since the type SqlDbType.Int represents a signed 32 bit integer...
1
2430
by: None | last post by:
Hi, I have to update my table using SqlParameter. Below is my code for update. cmdText = "update docs set Content = @content where DirName='" + DirName.Replace("'","''") + "' and LeafName='Hidden.txt'" SqlCommand cmd = new SqlCommand(); cmd.CommandText = cmdText; cmd.Connection = con;
4
1316
by: Showjumper | last post by:
Do you all create dedicated data access layers for each project or do you create resuable ones that you can use over many projects. Also, in the data access layer, do you all create specific functions with the sql statements hardcode into each and every function or just make a generic function and pass it different sql statments? Thanks...
5
363
by: dave | last post by:
I am calling a shared fucntion within a class from codebehind with asp.net. The class returns a sqldatareader to be bound to a datalist. I am also utilizing ms applicationblocks. How can I return the datareader from the shared function so that the datareader is closed properly after it has been bound th dave
6
2029
by: Joey Liang via DotNetMonster.com | last post by:
Hi all, I have a drop down list which store all the different brands of product.When i selected the particular brand from the drop down list, it will display all the products with the selected brand in a datagrid. I have this error when i select a brand from the drop down list. Blow is my code,anyone can help me to solve my error,which part of my code went wrong? Really thanx and very appreciate your help in advanced.. I have been stucked...
3
1393
by: JimG | last post by:
In Microsofts Application blocks they comment the code directly in front of the Sub or Function, (an example is below). These commented lines allow the programmer to see the comments and parameters when using that sub/function. I've tried to do this and I can't get it to work (see my code below). Does anyone have any ideas or know of any white papers? Microsofts code ' This method opens (if necessary) and assigns a connection,...
2
2810
by: timpera2501 | last post by:
I am a newb to OOP programming and I'm only just starting with C#. I've done a TON of reading lately, and I'm currently in the process of modifying some of the function provided by the "TimeTracker Start-up Kit" for my needs. ****** BEGINING OF TIME TRACKER SUMMARY ***** First, in the "TimeTracker Start-Up Kit" they appear to have tried to set it up so that it can be expanded to any number of different datasource types (SQL, Access,...
3
1313
by: Ashish | last post by:
hi All, Iam facing a peculiar problem, where i would like to parse the passed parameters and would like to figure out which ones are marked 'out'. For example the method signature is public DataSet SearchItems(string procname, params objects values) { // call database here }
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10778
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10210
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9319
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7750
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3077
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.