Populating the DataBase problem

Reply

Join Date: Nov 2007
Posts: 18
Reputation: AniWeb is an unknown quantity at this point 
Solved Threads: 0
AniWeb AniWeb is offline Offline
Newbie Poster

Populating the DataBase problem

 
0
  #1
Jan 14th, 2008
Hello All,

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

  1. <% dim stud1
  2. set stud1=server.createobject("adodb.connection")
  3. stud1.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("amitdatabase.mdb")
  4. %>
  5. <% dim stud2,stud3
  6. set stud2=server.createobject("ADODB.Recordset")
  7. stud3 = "SELECT tblComments.Name, tblComments.Comments FROM tblComments;"
  8. stud2.CursorType = 2
  9. stud2.lockType = 2
  10.  
  11. stud1.open stud2,stud3
  12. %>
  13. <%
  14. stud2.addnew
  15. stud2("firstname")=request.form("one")
  16. stud2("lastname")=request.form("two")
  17. stud2("email")=request.form("three")
  18. stud2("username")=request.form("four")
  19. stud2("password")=request.form("five")
  20. stud2.update
  21. %>

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
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 16
Reputation: Shailesh25 is an unknown quantity at this point 
Solved Threads: 1
Shailesh25 Shailesh25 is offline Offline
Newbie Poster

Re: Populating the DataBase problem

 
0
  #2
Jan 17th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Populating the DataBase problem

 
0
  #3
Jan 17th, 2008
Try this, and I'll let you know where you made mistakes
  1. <%
  2. dim stud1, stud2, stud3
  3. set stud1 = server.createobject("adodb.connection")
  4. '''You do not open the connection string, you need to set the provider:
  5. '''stud1.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & '''Server.MapPath("amitdatabase.mdb")
  6. stud1.Provider "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("amitdatabase.mdb") & ";"
  7.  
  8. '''no need to close and reopen asp brackets.
  9.  
  10. set stud2 = server.createobject("ADODB.Recordset")
  11. '''You don't have to put the table name infront of the column UNLESS you are using
  12. '''more than 1 table, so keep it simple!
  13. '''stud3 = "SELECT tblComments.Name, tblComments.Comments FROM tblComments;"
  14. stud3 = "SELECT Name, Comments FROM tblComments"
  15. '''You may or may not need these two lines below, depending on what you play on doing
  16. '''with your database (reading, writing, deleting, paging, etc.)
  17. '''if you have problems after this, try removing the next two lines, or commenting them out.
  18. stud2.CursorType = 2
  19. stud2.lockType = 2
  20.  
  21. '''Now would be the time to open the connection!
  22. stud1.Open
  23. '''You already opened stud1, now you need to open your recordset!
  24. '''stud1.open stud2,stud3
  25. '''You open your recordset with the query (stud3), on the following connection (stud1)
  26. stud2.open stud3, stud1
  27.  
  28. '''no need to close and reopen asp brackets.
  29.  
  30. stud2.addnew
  31. stud2("firstname")=request.form("one")
  32. stud2("lastname")=request.form("two")
  33. stud2("email")=request.form("three")
  34. stud2("username")=request.form("four")
  35. stud2("password")=request.form("five")
  36. stud2.update
  37. '''You should add a Requery to this, it redoes the update to ensure no columns were missed.
  38. '''if you have problems, remove requery statement. Sometimes it produces an error.
  39. stud2.requery
  40.  
  41. '''Don't forget to close the connection, or you will have major problems!
  42. stud1.Close
  43.  
  44. '''Set them to nothing
  45. stud1 = ""
  46. set stud1 = nothing
  47. stud2 = ""
  48. set stud2 = nothing
  49. %>
Last edited by SheSaidImaPregy; Jan 17th, 2008 at 10:25 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 16
Reputation: Shailesh25 is an unknown quantity at this point 
Solved Threads: 1
Shailesh25 Shailesh25 is offline Offline
Newbie Poster

Re: Populating the DataBase problem

 
0
  #4
Jan 18th, 2008
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
%>
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Populating the DataBase problem

 
0
  #5
Jan 18th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for ASP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC