PDA

View Full Version : inputing data into DB...need some help


Thimo
09-26-2002, 06:26 AM
<%
Dim Conn, myDSN, mySQL

myDSN="Stationary" '
mySQL="INSERT INTO Publishers (FirstName, LastName) VALUES ('Jon', 'Doe')"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open(myDSN)
Conn.Execute(mySQL)
Conn.Close
Set Conn = Nothing
%>

anything wrong?.....when i run this webpage, then i run the DB....the data inside is empty

i put this inside the body of the html tag......

Thatguy2001au
09-26-2002, 01:13 PM
Try this, hope it works:

Dim Conn, myDSN, mySQL

set Conn = Server.CreateObject("ADODB.Connection")
myDSN = "Data Source=Stationary;UID=;PWD=;"
Conn.Open myDSN

mySQL="INSERT INTO Publishers (FirstName, LastName) VALUES ('Jon', 'Doe')"

Conn.Execute mySQL

Conn.close
set Conn = Nothing

Thatguy2001au
09-26-2002, 01:15 PM
Sorry, i forgot one thing. Don't forget of course the usual
<%
%>
and also place the code in the <head> section of your webpage.

Mhtml
09-26-2002, 02:22 PM
Place it before the <html> tag and under any @ comands if you have any.

Make sure that the table exists.

this will work:

<%
Set ConnSQL = Server.CreateObject("ADODB.Connection")
path = Server.MapPath("databases/odysseystats.mdb")
ConnSQL.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & path

sqlInsert = "INSERT INTO Publishers (FirstName,LastName) VALUES ('John','Doe')"
ConnSql.Execute(sqlInsert)
%>

<%
ConnSQL.Close
Set ConnSQL = nothing
Set RS = nothing
%>



This uses a DSN less connection string, so you have to replace the path of the database with your own.