4 Replies - 9880 Views - Last Post: 24 April 2009 - 03:02 PM Rate Topic: -----

#1 rajnivas  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 21
  • Joined: 02-April 09

how to convert varchar to int

Post icon  Posted 24 April 2009 - 01:38 PM

hi,
how to convert varchar to int.i am using mysql
	uint m =Convert.ToUInt32(qe.Tables[0].Rows[0]["id"]);		\\here i want to convert varchar to int

 string ru = " SELECT name FROM syscolumns WHERE  id = 'm' ";	\\i am using here(id is int) & (m is in  varchar)

			   SqlCommand cl = new SqlCommand(ru, con);
				 DataSet qt = new DataSet();
				DataTable dn = new DataTable();
				SqlDataAdapter au = new SqlDataAdapter(cl);
				au.Fill(qt, "+v+");
				au.Fill(dn);



Is This A Good Question/Topic? 0
  • +

Replies To: how to convert varchar to int

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9278
  • View blog
  • Posts: 34,789
  • Joined: 12-June 08

Re: how to convert varchar to int

Posted 24 April 2009 - 01:48 PM

is the varchar a numeric character or alpha numeric?
Was This Post Helpful? 0
  • +
  • -

#3 rajnivas  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 21
  • Joined: 02-April 09

Re: how to convert varchar to int

Posted 24 April 2009 - 01:54 PM

View Postmodi123_1, on 24 Apr, 2009 - 12:48 PM, said:

is the varchar a numeric character or alpha numeric?


Quote

it is numeric character

Was This Post Helpful? 0
  • +
  • -

#4 egof  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 132
  • Joined: 27-March 09

Re: how to convert varchar to int

Posted 24 April 2009 - 01:54 PM

Looks like you buried your variable m inside your string
try this
string ru = " SELECT name FROM syscolumns WHERE  id = " + m;


Was This Post Helpful? 1
  • +
  • -

#5 Typewriter  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 01-October 08

Re: how to convert varchar to int

Posted 24 April 2009 - 03:02 PM

At the minute you have this, I'm not sure why your using unit exaclty, but could it not be held in a string instead?

Quote

uint m =Convert.ToUInt32(qe.Tables[0].Rows[0]["id"]); \\here i want to convert varchar to int

string ru = " SELECT name FROM syscolumns WHERE id = 'm' ";


You could try the following, not sure if it will work but you need to be passing a string or character into a SQL statement to get the right stuff returned as far as I know.

This will convert the tables part to an int, and then that to a string. Probably not the most efficent way but it might work.

If the stuff in the tables is not an integer then this will not work and neither would have the previous method.


int x = int.Parse(qe.Tables[0].Rows[0]["id"]);  

string m = x.ToString();

string ru = " SELECT name FROM syscolumns WHERE  id = 'm' "; 



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1