<i><b>Originally posted by : Martijn (mvdee@hotmail.com)</b></i><br /><br />Hai there,<br /><br />I've got written a asp script to input data into a database. The only thing is that the info is in integers. I don't know how to change those into doubleprecision. Underneath is my asp script. Who can help me??<br /><br />thanks Martijn<br /><br /><br /><%<br />' Just in case you're not up on my acronyms:<br />' DB = database, RS=recordset, CONN=connection<br />' o/w = otherwise<br /><br />' Include the VBScript ADO constants file<br />%><br /><!-- #INCLUDE FILE="adovbs.inc" --><br /><%<br />' *** Begin DB Setup ***<br />Dim strConnString<br />' Sample access OLEDB CONN String.<br />strConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _<br /> Server.MapPath("....mijn documentenafstuderen estemmingsplan wilhelminapark1.mdb") & ";"<br /> <br /><br /> <br />' Override with our site-wide CONN string.<br />'strConnString = Application("SQLConnString")<br /><br />' Access likes #, but SQL Server expects ' so you'll need to change<br />' this based on the DB you're using.<br />Const DATE_DELIMITER = "'"<br />' *** End DB Setup ***<br /><br />Dim cnnFormToDB ' CONN object<br />Dim strSQL ' String in which to build our SQL command<br />Dim lngRecsAffected ' # of records affected... just informational<br /><br />' Vars for the fields read in from the form. All fields are read<br />' in as strings so I need to covert them to the appropriate data<br />' types to be sure they're appropriate for the DB fields. These<br />' variables give me some working space to do this easily.<br />Dim strTextField ' text field <br />Dim adDoublefield ' integer field <br />Dim intIntegerField2 ' Het tweede integer field<br />Dim datDateTimeField ' date field<br /><br />Dim strErrorMsg ' Holds error message if we catch any problems.<br /><br /><br />' See if we have any info to process.<br />' If we don't (ie. the first time through) we just show<br />' the form. If we do we proceed with the insert.<br />If Request.Form("action") <> "Save Form Data" Then<br /> ' Show the form<br /> %><br /> <FORM ACTION="<%= Request.ServerVariables("SCRIPT_NAME") %>" METHOD="post"><br /> <INPUT TYPE="hidden" NAME="action" VALUE="Save Form Data"><br /> <TABLE BORDER="0"><br /> <TR><br /> <TD ALIGN="right"><B>Uw naam:</B></TD><br /> <TD ALIGN="left"><INPUT TYPE="text" NAME="Naam" MAXLENGTH="10"></TD><br /> </TR><br /> <TR><br /> <TD ALIGN="right"><B>De lengte van uw dakkapel (in m):</B></TD><br /> <TD ALIGN="left"><INPUT TYPE="text" NAME="Dakkapellengte"></TD><br /> </TR><br /> <TR><br /> <TD ALIGN="right"><B>De lengte van uw gevel(in m):</B></TD><br /> <TD ALIGN="left"><INPUT TYPE="text" NAME="Gevellengte"></TD><br /> </TR><br /> <TR><br /> <TD ALIGN="right"><B>De datum:</B></TD><br /> <TD ALIGN="left"><INPUT TYPE="text" NAME="Datum"></TD><br /> </TR><br /> <TR><br /> <TD> </TD><br /> <TD><br /> <INPUT TYPE="reset" VALUE="Clear"><br /> <INPUT TYPE="submit" VALUE="Save"><br /> </TD><br /> </TR><br /> </TABLE><br /> </FORM><br /> <%<br />Else<br /> ' Do our DB insert!<br /><br /> ' Retrieve the 4 strings to be entered into the DB<br /> strTextField = Request.Form("Naam")<br /> adDoublefield = Request.Form("Dakkapellengte")<br /> intIntegerField2 = Request.form("Gevellengte")<br /> datDateTimeField = Request.Form("Datum")<br /><br /> ' Start error handling... I'm too lazy to check all the criteria<br /> ' on my own so I use VBScript to do it for me. I simply do a<br /> ' conversion the the expected type and if it fails I catch the<br /> ' error, abort the insert, and display a message.<br /> On Error Resume Next<br /> strErrorMsg = ""<br /> <br /> ' String (text) field:<br /> ' Nothing should really go wrong here. It's already a string so<br /> ' I don't bother with a CStr. I do replace ' with '' for the<br /> ' validity our SQL statement and also check to make sure it's<br /> ' not an empty string. If it is an empty string ("") then I<br /> ' throw a fake error since I've already got this type of error<br /> ' handling in place... hey I already admitted I was lazy!<br /> strTextField = Trim(strTextField)<br /> If Len(strTextField) = 0 Or Len(strTextField) > 10 Then Err.Raise 1<br /> strTextField = Replace(strTextField, "'", "''")<br /> If Err.number <> 0 Then<br /> strErrorMsg = strErrorMsg & "Your entry for string_field is " & _<br /> "inappropriate!<BR>" & vbCrLf<br /> Err.Clear<br /> End If<br /><br /> ' Integer field:<br /> ' Lots of possible problems here. First off it could be text and<br /> ' not a number at all! Even if it is a number, there are a lot<br /> ' of restrictions on integers. It needs to be a whole number and<br /> ' it's absolute value can't be bigger than around 32,000. Using<br /> ' CInt I don't have to worry about it though.<br /> adDoublefield = CInt(adDoublefield)<br /> If Err.number <> 0 Then<br /> strErrorMsg = strErrorMsg & "Your entry for integer_field could " & _<br /> "not be converted to an integer! Remember that integers " & _<br /> "need to be from -32,768 to 32,767.<BR>" & vbCrLf<br /> Err.Clear<br /> End If <br /> intIntegerField2 = CInt(intIntegerField2)<br /> If Err.number <> 0 Then<br /> strErrorMsg = strErrorMsg & "Your entry for integer_field could " & _<br /> "not be converted to an integer! Remember that integers " & _<br /> "need to be from -32,768 to 32,767.<BR>" & vbCrLf<br /> Err.Clear<br /> End If <br /> <br /> ' Date field:<br /> ' Well it needs to be a valid date. You can enter it in any format<br /> ' the computer can understand. Doing the CDate will not only make<br /> ' sure it's a date, but will also make them all nice and uniform!<br /> datDateTimeField = CDate(datDateTimeField)<br /> If Err.number <> 0 Then<br /> strErrorMsg = strErrorMsg & "Your entry for date_time_field could " & _<br /> "not be converted to an date variable!<BR>" & vbCrLf<br /> Err.Clear<br /> End If<br /><br /> ' I don't know if this is really documented or a hack,<br /> ' but it turns error trapping back off!<br /> On Error Goto 0<br /><br /> ' If we have an error in our error string then we show<br /> ' the error message o/w we proceed with the insert.<br /> If strErrorMsg <> "" Then<br /> ' Show the error message that got us here!<br /> Response.Write strErrorMsg<br /> Else<br /> ' Open connection to the DB<br /> Set cnnFormToDB = Server.CreateObject("ADODB.Connection")<br /> cnnFormToDB.Open strConnString, , , <br /> adDouble<br /><br /> ' Build our SQL String<br /> <br /> strSQL = ""<br /> strSQL = strSQL & "INSERT INTO dakkapel "<br /> strSQL = strSQL & "(Naam, Dakkapellengte, Gevellengte, Datum) " & vbCrLf<br /> strSQL = strSQL & "VALUES ("<br /> strSQL = strSQL & "'" & strTextField & "'"<br /> strSQL = strSQL & ", "<br /> strSQL = strSQL & adDoublefield <br /> strSQL = strSQL & ", "<br /> strSQL = strSQL & intIntegerField2 <br /> strSQL = strSQL & ", "<br /> strSQL = strSQL & DATE_DELIMITER & datDateTimeField & DATE_DELIMITER<br /> strSQL = strSQL & ");"<br /><br /> ' Execute the SQL command. I pass it a variable lngRecsAffected<br /> ' in which to return the number of records affected. I also tell<br /> ' it that this is a text command and it won't be returing any<br /> ' records... this helps it execute the script faster!<br /> ' And before you ask... I don't know, but YES IT IS OR!!!<br /> cnnFormToDB.Execute strSQL, lngRecsAffected, adCmdtext Or adExecuteNoRecords <br /> <br /> <br />' Dispose of the CONN object<br />' cnnFormToDB.Close<br />' Set cnnFormToDB = Nothing<br />' 'strConnString.Close<br /><br /><br />'even rekenen mag het of mag het niet??<br /><br />dim cnnwoondoeleinden<br />Dim strDBPath ' path to our Access database (*.mdb) file<br />Set cnnwoondoeleinden = Server.CreateObject("ADODB.Connection")<br />strDBPath = Server.MapPath("....mijn documentenafstuderen estemmingsplan wilhelminapark1.mdb")<br />cnnwoondoeleinden.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"<br /><br /><br />'Set vergelijkwaarde = cnnwoondoeleinden.execute ("SELECT [max breedte dakkapel in m] FROM woondoeleinden") <br /><br />'response.write vergelijkwaarde<br />'adDoublefield = CInt(adDoublefield)<br />If adDoublefield > 1.8 Then<br /> strErrorMsg = strErrorMsg & "mag niet" & vbCrLf<br /> Err.Clear<br /> else strErrorMsg = strErrorMsg &"mag wel" & vbCrLf<br /> Err.clear<br /> End If <br /><br />Response.Write strErrorMsg<br /><br /> ' Dispose of the CONN object<br /> cnnFormToDB.Close<br /> Set cnnFormToDB = Nothing<br /> <br /> ' Display a verification message and we're done!<br /> %><br /> <H2>Thanks for submitting your information to us!</H2><br /> <br /> <P><br /> <B>The resulting SQL statement was:</B><br /> <PRE><%= strSQL %></PRE><br /> </P><br /> <br /> <P><br /> <B>Number of records affected:</B> <%= lngRecsAffected %><br /> </P><br /> <%<br /> End If<br />End If<br /><br />%><br />
