PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

cast string to integer?

 
 
=?Utf-8?B?UGF1bA==?=
Guest
Posts: n/a
 
      14th Feb 2005
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.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGF1bA==?=
Guest
Posts: n/a
 
      14th Feb 2005
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.

 
Reply With Quote
 
Picho
Guest
Posts: n/a
 
      14th Feb 2005
you can also use Int32.Parse(string s)
or C# specific int.Parse(string s)

Picho


"Paul" <(E-Mail Removed)> wrote in message
news:01A41D61-A555-45C9-B331-(E-Mail Removed)...
>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.



 
Reply With Quote
 
Chad Z. Hower aka Kudzu
Guest
Posts: n/a
 
      14th Feb 2005
"=?Utf-8?B?UGF1bA==?=" <(E-Mail Removed)> wrote in
news:94ECF16D-8361-410B-8C57-(E-Mail Removed):
> 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/
 
Reply With Quote
 
=?Utf-8?B?UGF1bA==?=
Guest
Posts: n/a
 
      14th Feb 2005
ok thanks for the reply.

"Chad Z. Hower aka Kudzu" wrote:

> "=?Utf-8?B?UGF1bA==?=" <(E-Mail Removed)> wrote in
> news:94ECF16D-8361-410B-8C57-(E-Mail Removed):
> > 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/
>

 
Reply With Quote
 
=?Utf-8?B?UGF1bA==?=
Guest
Posts: n/a
 
      14th Feb 2005
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" <(E-Mail Removed)> wrote in message
> news:01A41D61-A555-45C9-B331-(E-Mail Removed)...
> >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.

>
>
>

 
Reply With Quote
 
Chad Z. Hower aka Kudzu
Guest
Posts: n/a
 
      14th Feb 2005
"=?Utf-8?B?UGF1bA==?=" <(E-Mail Removed)> wrote in
news:4C17B6DA-5B9D-4A99-8E86-(E-Mail Removed):
> 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/
 
Reply With Quote
 
=?Utf-8?B?UGF1bA==?=
Guest
Posts: n/a
 
      14th Feb 2005
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==?=" <(E-Mail Removed)> wrote in
> news:4C17B6DA-5B9D-4A99-8E86-(E-Mail Removed):
> > 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/
>

 
Reply With Quote
 
rk
Guest
Posts: n/a
 
      14th Feb 2005
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

 
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
Cast Integer as Boolean? Joel Whitehouse Microsoft VB .NET 12 6th Aug 2005 12:27 AM
Cast from string to type integer Bob Microsoft ADO .NET 9 5th Jul 2005 07:35 AM
Error: Cast From String to type Integer not valid =?Utf-8?B?TWljaGFlbA==?= Microsoft VB .NET 2 1st Jul 2005 07:26 PM
How to cast string to integer ad Microsoft C# .NET 2 28th Mar 2005 02:21 AM
newbie: How to cast a string into integer? Juan Microsoft C# .NET 8 23rd Mar 2004 06:50 AM


Features
 

Advertising
 

Newsgroups
 


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