Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
how to convert string to bigint in asp.net using c#.

I have taken Refid as Bigint.
So,i want to convert textbox value to BIGINT

SQL
Query = "select * from demo where Refid=" + __________(TextBox1.Text);
Posted
Updated 1-Jan-13 23:14pm
v2

You query is going to work just fine without any conversion. Just make sure that the value entered in the textbox is validated before sending to the query.
 
Share this answer
 
Comments
Herman<T>.Instance 2-Jan-13 5:15am    
he can use string.format to assist him:
Query = string.Format("select * from demo where Refid={0}", TextBox1.Text);
Hi,

You can use the following things for conversion.
C#
textboxvaluehere.ToInt64();
Convert.ToInt64(textbox value here);

Int64.Parse(textbox value here);
Int64.TryParse(your textbox value, out parameter);


Use any one of these method and you will get the integer to be parsed. But remember that your textbox contains a valid input.

Thanks
 
Share this answer
 
v2
It is easiest to use Convert.ToInt e.g. select * from demo where Refid=" + Convert.ToInt64(TextBox1.Text); .

However, this can be a problem if you are not sure if the string is an integer.
In this case, you can consider using Int64.TryParse[^].
 
Share this answer
 
I think you no need to convert string to bigint.
C#
Query = String.Format("select * from demo where Refid={0}" ,TextBox1.Text)
 
Share this answer
 
hi,

Use this one :-

Int64 refId=0;
Int64.TryParse(TextBox1.Text, out refId);
 
Share this answer
 
You can use either Int64.TryParse or Convert.ToInt64
 
Share this answer
 
Try this

C#
Query = "select * from demo where Refid=" + Convert.ToInt64(TextBox1.Text);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900