3 Replies - 11909 Views - Last Post: 01 October 2012 - 02:57 AM Rate Topic: -----

#1 ponnu2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-September 12

vb6 to connect to acess database and insert records into the table

Posted 27 September 2012 - 11:59 PM

GIVEN below is vbscript to connect to acess database and insert records into the table using forms

Private Sub Command1_Click()

Set rs = cn.Execute("insert into employee values('txtempname.text',txtempid.text,txtssn.text) ")
rs.Close
cn.Close
End Sub

Private Sub Form_Load()
datafile = "C:\mas.accdb"
With cn
.Provider = "microsoft.ACE.OLEDB.12.0"
.ConnectionString = datafile
.Open

End With
End Sub

GLOBAL SECTION

Global cn As New ADODB.Connection
Global rs As New ADODB.Recordset
Global datafile As String





I am getting error "no value given for one or more parameters ".please help me to fix this error?

Is This A Good Question/Topic? 0
  • +

Replies To: vb6 to connect to acess database and insert records into the table

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4399
  • View blog
  • Posts: 12,253
  • Joined: 18-April 07

Re: vb6 to connect to acess database and insert records into the table

Posted 28 September 2012 - 04:35 PM

I think you should check out connectionstring.com for setting up your connection string to MS Access. I would recommend you either go with standard security for OLE DB 4.0 or scroll down to the ODBC section.

Here is an example of how you might go about doing this...

Public Sub Connect()
cn.CursorLocation = adUseClient

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mas.accdb;User Id=Username;Password=Userpass;"

cn.Open strConn



Then you can create an ADODB.Command object and recordsets based off of this connection. Below is a link to an example...

http://www.timesheet...adotutorial.htm

Play around with that and you can get a better idea of how this all works. :)
Was This Post Helpful? 0
  • +
  • -

#3 Tolerated  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-September 12

Re: vb6 to connect to acess database and insert records into the table

Posted 29 September 2012 - 10:18 AM

Why dont you just add a data property to your form then add some text boxes and an add button with the code
data1.recordset.addnew
this would automatically add all the data that is in the text boxes but make sure you link each one before doing this.
Was This Post Helpful? 0
  • +
  • -

#4 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: vb6 to connect to acess database and insert records into the table

Posted 01 October 2012 - 02:57 AM

this is because your insert query is wrong
change the insert query like this
"insert into employee values('"+ txtempname.text+ "', "+ txtempid.text +", "+txtssn.text +" ) "


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1