Converting a string to a number

Hello everyone, first post and all that, i got a bit of a problem.

First off, the DB information:
id: autonumber
score: text
Both these feilds in the database are numerical, however, the score is used as a text feild, the id an autonumber.
When i use a querystring to pass the score over to another page, so that the page produces only information with that perticular score matching, it works.
When i try to use the ID number, i get a case miss match.
I can only fathom that this is because its an autonumber. However, i need to keep the DB design as it is, as when i add a new article to the Database, the ID number is autogenerated and doesnt duplicate.
Is there anyway i can convert the value of ID from text to a number so that i can pull the information out of the DB?
Thanks.
0
northern_monkey
2/25/2005 12:15:52 PM
asp.net.getting-started 91979 articles. 0 followers. Follow

5 Replies
80 Views

Similar Articles

[PageSpeed] 6

Can we see the code that is giving you trouble?

Terri
Terri Morton
Engagement Manager, Neudesic

How to ask a question

0
tmorton
2/25/2005 1:06:45 PM
on the page where all reviews are selected


<a href=review.aspx?title=<%# Container.DataItem("id") %>>Read</a>

--
the reviews page (where the information should be called up)

sub page_load
dim id = request.QueryString("id")

dim dbconn,sql,dbcomm,dbread
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("nbc.mdb"))
dbconn.Open()
sql="SELECT * FROM nbcreview where id='" & id & "'"
dbcomm=New OleDbCommand(sql,dbconn)
dbread=dbcomm.ExecuteReader()
user.DataSource=dbread
user.DataBind()
dbread.Close()
dbconn.Close()
end sub

If i change the query string to a text feild, it will work...if i try it with the id feild (which is an autonumber) it doesnt work and gives me a type missmatch error.
0
northern_monkey
2/25/2005 1:10:56 PM
Remove single quote from your query if the field is integer.

sql="SELECT * FROM nbcreview where id=" & integer.Parse(id )
It should work
Arvind Malik
0
arvind2004
2/25/2005 1:29:54 PM
Please never concatenate data into a SQL string to be executed!  This is opening your website up to SQL injection attacks.  Instead use parameters.

The end part of your code would be better like this:

sql="SELECT * FROM nbcreview where id=@ID"
dbcomm=New OleDbCommand(sql,dbconn)
dbcomm.Parameters.Add("@ID", OleDbType.Integer).Value=ID
dbread=dbcomm.ExecuteReader()
user.DataSource=dbread
user.DataBind()
dbread.Close()
dbconn.Close()

Terri
Terri Morton
Engagement Manager, Neudesic

How to ask a question

0
tmorton
2/25/2005 1:42:28 PM
Thanks a lot, it is working now.

I also spotted a glaring error in my programming (as usual).
On the first part of the code, the querystring was named title (after another test), though i changed it on local machine, i forgot to upload it.
D'oh.
Either way, it is working fine now, thanks for the help, expect a few more posts in the coming months. This site is for my dissertation at university and ive never programmed asp.net before (though can do asp and php)
Thanks again for the help guys!
0
northern_monkey
2/25/2005 1:44:17 PM
Reply:

Similar Artilces:

convert string to smallint
Hi, what is the best way to convert a string to a smallint datatype?  You can use the int16 or Int data type instead.. so trystring str = "50"; Int16 val = Int16.Parse(str);OR Int16 val = Convert.ToInt16(str); Regards,Vinz"Code, Beer and Music" that's my way of being a programmer!How to get your Forum Question Answered | Blog | CodeASP.NET if u r using vb.netConvert.ToInt16()in case of c#  Int16.Parse Thank uBabaPlease remember to click "Mark as Answer" on this post if it helped you. Hi, Srijaya, Convert.ToInt16(str) and Int1...

how to get the buffer size of a string #2
-------------------------------1079023166 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Is there a function to get the buffer size? -------------------------------1079023166-- ...

How to convert XE4 from XE2 ? ( iOS Style Code ) [Edit]
Hello. In my case, I want to using Delphi XE4 with FMX or without FMX for small executable size. How to convert this code from XE2 ? I translate the code following. Of course, It crashed when running. What's wrong in code ? or Completely misunderstanding ? Thanks. In Case of XE2, FPC, It works. {code} // XE2, Free Pascal Compiler 2.7.1 - iOS "Hello World" program test; {$modeswitch ObjectiveC1} uses iPhoneAll; type AppDelegate = objcclass(UIResponder, UIApplicationDelegateProtocol) private window : UIWindow; viewcontr...

convert jpg to bmp
I am running PB6.0 and have a window that displays bmp pictures. The supplier of the pictures can only deliver jpg files. I can recieve upto 2000 pictures at a time and need a way to convert the jpg to bmp files easily. Is there code or a dll or some other means that I can access to do this conversion with a small program. Thanks Check out PaintShop Pro Steven Schlossberg wrote in message ... >I am running PB6.0 and have a window that displays bmp pictures. The supplier >of the pictures can only deliver jpg files. I can recieve upto 2000 pictures at >a time and nee...

Limiting the number of recipients
I'm sure this has been asked before, but is there a way in GW 7 to limit the number of recipients a user can send to in one outbound message? I was using Netmail in the past for our student email system and I could set a limit of 10 recipients per message but I am not sure if it is possible or where to find it in the GW configuration. Thanks, Richard G. Not possible with GW, sorry Cheers Dave -- Dave Parkes [NSCS] Occasionally resident at http://support-forums.novell.com/ ...

SQL connection string problems
I have two version of SQL on the same server (2000 and 2005). The named instance of 2005 is SQL2005.  When I try to connect to the database in this server, it failed. Here is my connection string  data source=MyServerName\\SQL2005; Integrated Security=SSPI; Database=MyDataBase; I know that this connection string works if I only have one SQL instance on the server. But with two instances of SQL (different version) on one server, I am really confused now.  How should my connection string look like?  Thanks Michael  huangdashi Try this : "data source=MyServerN...

Formatting a Phone Number Entry Field!
Hello, I have an existing asp.net page that asks for a customer's US phone number. Unfortunately, the field is set up to only accept entries in an unbroken number string, i.e. 6178899923instead of the more familiar US formats such as:617-889-9923 or (617) 889-9923  (the form now returns an error when numbers are entered in this way)How might I set up the field to accept phone numbers in one of these formats? I don't care as much how the number is stored in SQL, rather I want to make it easier for the customer. For reference:<code><tr>       &nbs...

converting
How can convert a mdb to mdf file Microsoft Access to SQL server file !? ? Many ThankS Access has an Upsizing Wizard that will do this for you. Tools > Database Utilities > Upsizing Wizard.Lex Barr bBounce.com - Automatic email bounce handler. TestData.com - Create meaningful test data to test your database applications....

Pascal to C# converter?
Anyone seen such a beast or done something related? Any experiences? I have ModelMaker, which can convert class structures, but the module code and method bodies are not converted. I could not find anything with a quick Googling either. I am not up to a 100% conversion, at least not yet :) TIA, Jouni Aro Prosys Jouni Aro wrote: > Anyone seen such a beast or done something related? Any experiences? Compile the code in Delphi for .NET and then look at the result in Reflector. This has a filter for both languages. <g> -- Rudy Velthuis (TeamB) http:/...

convert date & time to timestamp
Hi, I have two columns.. one is date & one is Time.. I want to concatenate it and compare with another Timestamp field.. How can I do..? Thanks. cast( dateCol + timeCol as datetime ) as dateTimeCol, -- Paul Horan[TeamSybase] "Chandu" <chandrasekhars@stcroixsystems.com> wrote in message news:410e6a0b@forums-1-dub... > Hi, > > I have two columns.. one is date & one is Time.. > I want to concatenate it and compare with another Timestamp field.. > How can I do..? > > Thanks. > > It is possible (depending on you...

increase number of user connections
Hi folks, I have a SUN E4500 with 2 CPU and 4GB RAM with 2 ASE 11.9.2 (datapopulation and one standby)and a Replicationserver. (max online engines 1 because 2 CPU). With SELECT @@max_connections I get 1014. The following web-application needs approx. 3000 user connections, but I can configure only ca. 800. by the way: I've try it with ulimit -Sn 1024, but without success - the value from @@max_connections dosn't change Is there any way to increase the number of user connections without build in new CPUs (and increase max online engines)? hope for your help In...

Strings for iOS
I noticed that Apple has made a huge amount of localized strings for iOS available to developers: https://developer.apple.com/downloads/index.action?name=localization# "The newest translations of strings from iOS 7.1 are available here. These files can be used by AppleGlot as translators to help streamline the localization process. These files can all be viewed with TextEdit in Mac OS X". I see it has for example strings like this: <TextItem> <Description/> <Position>The certificate for this website is not yet valid. Tap Accept to co...

mobile application
Hi, The task I have is to create a library of articles (about 100 articles) for PDA's. This library would be available for download on my site. The users should be able to download this and later sync it with their PDA's These articles are already in  a SQL Server 2000 dB. What is the best way to do this? I want to know how I can format these articles in a way that can be easily read on a PALM or pocket pc, I would like to provide a TOC. I would really appreciate if you can send me code or redirect me to links that would help me complete this task. Please f...

using soundx() in c#.net for string comparision
hi i have to compare strings which sounds same ex: i wanted to look at all rows that sound like "Erickson," so it should find those with "Erickson," "Erikson," "Ericson," "Ericksen," "Ericsen," how to use this in asp.net(c#)? could any one help me with this thanks   There is no built-in function in .NET to perform a soundex comparison. There is however a number of third-party implementations of this algorithm (or rather algorithms). See this article from CodeProject for an example.I've been using the SOUNDEX fun...

Powerbuilder Nested datawindow Page Number & Overlap problem
Powerbuilder version 6.0.00 Oracle 8 If one of the nested datawindow is carried over to next page, the page number is supposed to be incremented. But it comes up with previous page number. The page number shown on the report is page 1, 2, 2, 4. Is there any way I can get around in version 6.0.00. I tried this in PB version 6.5. It works correctly. If I migrate my project to version 6.5, is there any known migration problem?? (The reason is I tried to migrate a project from PB 4.0 to PB 5.0.4. The match function is not working the same as PB 4 or PB 6. I got a GPF error wh...