Jump to content

ASP: Data Type Mismatch


Recommended Posts

Hi to all msfn members!

I made a form with 2 textbox in html. in the database, I have 1 of type numeric and the other of date / time. I supply the right input for the two textboxes, meaning, I input for example 1 on first textbox and 2/23/2005 on the second box, everything is saved well on the database. but when i input 'abc' on first textbox and 'abcd' on the second box, it displays an error message "data type mismatch". Can you guys help me how to troubleshoot this error? I need your help a.s.a.p. tnx a lot!

Link to comment
Share on other sites


well i dont know asp but what type of variable did u set it to be in the database? is it a text string? b/c data type mismatch would be like if you were trying to enter "abc" into a variable that only accepts numbers.

Link to comment
Share on other sites

Why would you pick classic ASP nowadays? I can't think of a single good reason to use that (as much as I dislike PHP - and dislike is quite an understatement here - I'd even use that before). If you're gonna go the Microsoft way, ASP.NET is where it's at. Classic ASP is 10 year old tech (the NT4 days)... And ASP.NET isn't anything new either (been around since 2002, the 4th version of the .NET framework is coming up soon). Classic ASP is pretty much inferior to anything I can think of. ASP.NET has rich frameworks, great OO languages, proper error handling, better dev tools, scales better, more maintainable, more secure, faster to develop, far more stable, more flexible, ridiculously more powerful, etc (I could go on for days, but having an edge over classic ASP isn't exactly something to brag about either)

Look like you got several issues...

-Using the wrong, outdated tech (IMHO)

-Trying to enter an invalid data type (string into a numeric column? or a date/time?) and not understanding the (rather helpful) error message (I don't wanna bash anyone, but this is very, very basic stuff we're talking about here)

-Obviously, no server-side, nor client-side validation is done (and that's a VERY, VERY BAD thing!). There is NO excuse for not doing this - at the VERY LEAST server-side (and display validation errors on the form/page - not have the page crash like that and display server errors for such things). Preferably, using Regular Expressions, and also doing client-side validation in javascript (onchange/onsubmit). And while we're on that subject, date handling is a fun thing. You're assuming ppl will always enter MM/DD/YYYY it seems... Ideally you use the ISO date format (internally at least). Server/client/database/regional settings and what not can bite you in the a** here...

-Likely, you're using string concatenation to generate dynamic SQL (which is again VERY, VERY BAD - 100% exposed to very basic SQL injection attacks, and n00b can TOTALLY hack this without even having to think). The very minimal thing to do (and I'd call that quite a ugly hack) is escaping strings, although parameterized queries is what one ought to use (sprocs not a bad idea either). No idea what DB you're using, nor if you're using the right proivider for it either or anything like that (not enough details - just hoping it ain't jet/access! *shudders*).

It may sound harsh, but don't take it as bashing. More like an eye opener perhaps. If you want to find out how to do this properly, there are loads - and I mean LOADS of good infos out there... Like the ASP.NET quickstarts, starter kits, sample code everywhere, MSDN, endless webcasts, training DVDs available for the price of shipping, MS eLearning offers (lots of free courses), tons of community websites, etc... And there are even some great free dev tools (Visual Web Developper namely). There are many excellent (powerful, fast, secure, ...) and free enterprise grade RDBMS'es as well (SQL Server Express as well as DB2 and Oracle express, PostgreSQL, etc).

Even if I decided against ASP.NET, I *still* wouldn't do classic ASP.

Link to comment
Share on other sites

  • 4 weeks later...
Why would you pick classic ASP nowadays? I can't think of a single good reason to use that (as much as I dislike PHP - and dislike is quite an understatement here - I'd even use that before). If you're gonna go the Microsoft way, ASP.NET is where it's at. Classic ASP is 10 year old tech (the NT4 days)... And ASP.NET isn't anything new either (been around since 2002, the 4th version of the .NET framework is coming up soon). Classic ASP is pretty much inferior to anything I can think of. ASP.NET has rich frameworks, great OO languages, proper error handling, better dev tools, scales better, more maintainable, more secure, faster to develop, far more stable, more flexible, ridiculously more powerful, etc (I could go on for days, but having an edge over classic ASP isn't exactly something to brag about either)

Look like you got several issues...

-Using the wrong, outdated tech (IMHO)

-Trying to enter an invalid data type (string into a numeric column? or a date/time?) and not understanding the (rather helpful) error message (I don't wanna bash anyone, but this is very, very basic stuff we're talking about here)

-Obviously, no server-side, nor client-side validation is done (and that's a VERY, VERY BAD thing!). There is NO excuse for not doing this - at the VERY LEAST server-side (and display validation errors on the form/page - not have the page crash like that and display server errors for such things). Preferably, using Regular Expressions, and also doing client-side validation in javascript (onchange/onsubmit). And while we're on that subject, date handling is a fun thing. You're assuming ppl will always enter MM/DD/YYYY it seems... Ideally you use the ISO date format (internally at least). Server/client/database/regional settings and what not can bite you in the a** here...

-Likely, you're using string concatenation to generate dynamic SQL (which is again VERY, VERY BAD - 100% exposed to very basic SQL injection attacks, and n00b can TOTALLY hack this without even having to think). The very minimal thing to do (and I'd call that quite a ugly hack) is escaping strings, although parameterized queries is what one ought to use (sprocs not a bad idea either). No idea what DB you're using, nor if you're using the right proivider for it either or anything like that (not enough details - just hoping it ain't jet/access! *shudders*).

It may sound harsh, but don't take it as bashing. More like an eye opener perhaps. If you want to find out how to do this properly, there are loads - and I mean LOADS of good infos out there... Like the ASP.NET quickstarts, starter kits, sample code everywhere, MSDN, endless webcasts, training DVDs available for the price of shipping, MS eLearning offers (lots of free courses), tons of community websites, etc... And there are even some great free dev tools (Visual Web Developper namely). There are many excellent (powerful, fast, secure, ...) and free enterprise grade RDBMS'es as well (SQL Server Express as well as DB2 and Oracle express, PostgreSQL, etc).

Even if I decided against ASP.NET, I *still* wouldn't do classic ASP.

I still programme in classic ASP because it does what I want and I dont have to learn a new language. I will move to ASP.NET in the future but just because something is "new" doesnt always mean it is better.

RJ

Link to comment
Share on other sites

I will move to ASP.NET in the future but just because something is "new" doesnt always mean it is better.

RJ

True to some extent. In the case of classic ASP, pretty much everything else is better. Not everything new is better, but .Net 2.0/C# is (or at least is amongst) the absolute best dev platform right now (IMHO), and ASP.Net is one of its strong points. It's truly great. Comparing it to what's more or less the worst...

You say it does what you want, but seeing your post, it doesn't seem so (having problems with newbie stuff on an extremely simple script and not making sense of it). Honestly, it looks like you more or less have to learn the whole thing anyways, why not learn the new and dramatically better way - or perhaps use something like PHP while you're not locked in, and that you seemingly only want a simple scripting language without steep learning curve and all (and it's free too and a whole lot cheaper to host on the web if you ever need to). There's tons of free learning material for all of them (I can post some if you're interested).

Your choice anyways. Best of luck to you.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...