Hello All,

I want to store data into MS Access database without using DSN (Data Source Name). For his I have done the coding:-

<% dim stud1
set stud1=server.createobject("adodb.connection") 
stud1.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("amitdatabase.mdb")  
%>
<% dim stud2,stud3  
set stud2=server.createobject("ADODB.Recordset")
stud3 = "SELECT tblComments.Name, tblComments.Comments FROM tblComments;"  
stud2.CursorType = 2 
stud2.lockType = 2 

stud1.open stud2,stud3
%>
<%
stud2.addnew
stud2("firstname")=request.form("one")
stud2("lastname")=request.form("two")
stud2("email")=request.form("three")
stud2("username")=request.form("four")
stud2("password")=request.form("five")
stud2.update
%>

Using this coding I am unable to send data to database from the Form. And I also do not getting any error messages.

Anyone please help me to solve this problem.

Thanks

comment following lines
'stud1.open stud2,stud3

'stud2.CursorType = 2
'stud2.lockType = 2

and instead of this
'stud1.open stud2,stud3
write this
stud2.open stud3,stud1

Try this, and I'll let you know where you made mistakes

<%
dim stud1, stud2, stud3
set stud1 = server.createobject("adodb.connection") 
'''You do not open the connection string, you need to set the provider:
'''stud1.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & '''Server.MapPath("amitdatabase.mdb")  
stud1.Provider "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("amitdatabase.mdb") & ";"

'''no need to close and reopen asp brackets.

set stud2 = server.createobject("ADODB.Recordset")
'''You don't have to put the table name infront of the column UNLESS you are using
'''more than 1 table, so keep it simple!
'''stud3 = "SELECT tblComments.Name, tblComments.Comments FROM tblComments;"  
stud3 = "SELECT Name, Comments FROM tblComments"
'''You may or may not need these two lines below, depending on what you play on doing
'''with your database (reading, writing, deleting, paging, etc.)
'''if you have problems after this, try removing the next two lines, or commenting them out.
stud2.CursorType = 2 
stud2.lockType = 2 

'''Now would be the time to open the connection!
stud1.Open
'''You already opened stud1, now you need to open your recordset!
'''stud1.open stud2,stud3
'''You open your recordset with the query (stud3), on the following connection (stud1)
stud2.open stud3, stud1

'''no need to close and reopen asp brackets.

stud2.addnew
stud2("firstname")=request.form("one")
stud2("lastname")=request.form("two")
stud2("email")=request.form("three")
stud2("username")=request.form("four")
stud2("password")=request.form("five")
stud2.update
'''You should add a Requery to this, it redoes the update to ensure no columns were missed.
'''if you have problems, remove requery statement. Sometimes it produces an error.
stud2.requery

'''Don't forget to close the connection, or you will have major problems!
stud1.Close

'''Set them to nothing
stud1 = ""
set stud1 = nothing
stud2 = ""
set stud2 = nothing
%>

No need to write all this
just copy paste following.

<% dim stud1
set stud1=server.createobject("adodb.connection")
stud1.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("amitdatabase.mdb")
%>
<% dim stud2,stud3
set stud2=server.createobject("ADODB.Recordset")
stud3 = "SELECT tblComments.Name, tblComments.Comments FROM tblComments;"
stud2.CursorType = 2
stud2.lockType = 2

'stud1.open stud2,stud3
stud2.open stud3,stud1

%>
<%
stud2.addnew
stud2("firstname")=request.form("one")
stud2("lastname")=request.form("two")
stud2("email")=request.form("three")
stud2("username")=request.form("four")
stud2("password")=request.form("five")
stud2.update
%>

All that it contained was comments, but almost exactly the same code that you have lol. I was just giving him a lesson so he knows what to do in the future.

This article has been dead for over six months. Start a new discussion instead.