469,290 Members | 1,868 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

cast string to integer?

I am new to C#, but have c experience. Anyhow I have a web application and
am just trying to get the selected value of a dropdown box in integer form so
I can pass it to a stored procedure, but cast from string to int is not
allowed.
any suggestions?
string s_user;
int i_user;
s_user = this.dr_user.SelectedValue;
i_user=(int)s_user;
--
Paul
thanks.
Nov 16 '05 #1
8 22262
got this to work, used Convert.ToInt32();

"Paul" wrote:
I am new to C#, but have c experience. Anyhow I have a web application and
am just trying to get the selected value of a dropdown box in integer form so
I can pass it to a stored procedure, but cast from string to int is not
allowed.
any suggestions?
string s_user;
int i_user;
s_user = this.dr_user.SelectedValue;
i_user=(int)s_user;
--
Paul
thanks.

Nov 16 '05 #2
you can also use Int32.Parse(string s)
or C# specific int.Parse(string s)

Picho
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:01**********************************@microsof t.com...
I am new to C#, but have c experience. Anyhow I have a web application and
am just trying to get the selected value of a dropdown box in integer form
so
I can pass it to a stored procedure, but cast from string to int is not
allowed.
any suggestions?
string s_user;
int i_user;
s_user = this.dr_user.SelectedValue;
i_user=(int)s_user;
--
Paul
thanks.

Nov 16 '05 #3
"=?Utf-8?B?UGF1bA==?=" <Pa**@discussions.microsoft.com> wrote in
news:94**********************************@microsof t.com:
got this to work, used Convert.ToInt32();


Its probably mute - but you cannot CAST a string to an integer. You have to
convert it - which you found the solution to already.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
Nov 16 '05 #4
ok thanks for the reply.

"Chad Z. Hower aka Kudzu" wrote:
"=?Utf-8?B?UGF1bA==?=" <Pa**@discussions.microsoft.com> wrote in
news:94**********************************@microsof t.com:
got this to work, used Convert.ToInt32();


Its probably mute - but you cannot CAST a string to an integer. You have to
convert it - which you found the solution to already.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/

Nov 16 '05 #5
ok thanks for the reply, just wondering if you know how to set a parameter
being passed to a stored procedure, Think I am close but get the error
denotes a property where a method was expected under the parameter key word.
thanks,
this.da_usrinfo.SelectCommand.Parameters("@User_Id ").Value = i_user;
"Picho" wrote:
you can also use Int32.Parse(string s)
or C# specific int.Parse(string s)

Picho
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:01**********************************@microsof t.com...
I am new to C#, but have c experience. Anyhow I have a web application and
am just trying to get the selected value of a dropdown box in integer form
so
I can pass it to a stored procedure, but cast from string to int is not
allowed.
any suggestions?
string s_user;
int i_user;
s_user = this.dr_user.SelectedValue;
i_user=(int)s_user;
--
Paul
thanks.


Nov 16 '05 #6
"=?Utf-8?B?UGF1bA==?=" <Pa**@discussions.microsoft.com> wrote in
news:4C**********************************@microsof t.com:
ok thanks for the reply, just wondering if you know how to set a
parameter being passed to a stored procedure, Think I am close but get
the error denotes a property where a method was expected under the
parameter key word. thanks,
this.da_usrinfo.SelectCommand.Parameters("@User_Id ").Value = i_user;


I havent looked at the reference, but try:
this.da_usrinfo.SelectCommand.Parameters["@User_Id"].Value = i_user;

Its probably a property and not a method.

--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/
Nov 16 '05 #7
got it to work used

this.da_usrinfo.SelectCommand.Parameters[1].Value = i_user;
thanks for the reply.
"Chad Z. Hower aka Kudzu" wrote:
"=?Utf-8?B?UGF1bA==?=" <Pa**@discussions.microsoft.com> wrote in
news:4C**********************************@microsof t.com:
ok thanks for the reply, just wondering if you know how to set a
parameter being passed to a stored procedure, Think I am close but get
the error denotes a property where a method was expected under the
parameter key word. thanks,
this.da_usrinfo.SelectCommand.Parameters("@User_Id ").Value = i_user;


I havent looked at the reference, but try:
this.da_usrinfo.SelectCommand.Parameters["@User_Id"].Value = i_user;

Its probably a property and not a method.

--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/

Nov 16 '05 #8
rk
Paul,

Basically you can look at the property of the selectcommand in the
property explorer window and it should show you all the parameters
associated with the command. By default, the first parameter (index 0)
is @RETURN_VALUE. Other params get listed below this. So, you and
Hower both are right and both calling mechanism should work fine
although the one suggested by Hower is more fool proof.

--rk

Nov 16 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Jay | last post: by
2 posts views Thread by ad | last post: by
3 posts views Thread by dbuchanan | last post: by
13 posts views Thread by archuleta37 | last post: by
1 post views Thread by =?Utf-8?B?U2lzbmF6?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.