473,394 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to add data in access using vb6

Hi, i need to extend my system functionality . I need to do add and edit function. Can anyone help me by guide how to do so ? I got error when i use this coding.
Expand|Select|Wrap|Line Numbers
  1. Dim cn1 As ADODB.Connection 
  2. Dim rs1 As ADODB.Recordset 
  3. Dim sqlString As String 
  4.  
  5. ' Add new record - 
  6. sqlString = "Insert INTO Alternator Engine,Volt,Amp)" _ 
  7. & " VALUES (" & txtAlternator.Text & "," & txtVolt.Text & "," & txtAmp.Text & ")" 
  8.  
  9. Set rs1 = cn1.Execute(sqlString) 
  10.  
  11. ' Clear the fields - 
  12. txtAlternator.Text = "" 
  13. txtVolt.Text .Text = ""  txtAmp.Text = ""
Apr 4 '08 #1
4 7228
jeffstl
432 Expert 256MB
Your SQL ordering\syntax is wrong.

The SQL syntax is as follows:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO [TableName] (fieldname,fieldname,fieldname) VALUES ('" & Value1 & "', '" & Value2 & "', '" & Value3 & "')
  2.  
  3.  
Your missing your table identifier. What table those fields are in.

Also, I COULD be wrong, but I don't think you can have a field name in a table with a space in it (Alternator Engine is not a valid name for a column, if you go check your table design I'm betting thats not the name)

So you need something like this instead:
Expand|Select|Wrap|Line Numbers
  1. sqlString = "Insert INTO MyTable (AlternatorEngine,Volt,Amp)" _ 
  2. & " VALUES ('" & txtAlternator.Text & "'," & txtVolt.Text & "," & txtAmp.Text & ")" 
  3.  
Also note that I have placed single quote ' around the txtAlternator.Text. This is because that is likely a string data type in your table design. Any string\text data type in a table will need the single quotes around it '" & x & "', if it is a number\integer\long then you just need the " & x & "
Apr 4 '08 #2
Dököll
2,364 Expert 2GB
Hey there!

You've come to the right place, although I am not too skilled in ADODB. I can post something in DAO that works just great:-)

Add reference to Microsoft DAO 3.06 Object Library

Expand|Select|Wrap|Line Numbers
  1. Private Sub subt_Click()   'this funtion will load entry into database
  2.  
  3.         Dim my_database As Database
  4.         Set my_database = OpenDatabase("C:\DataMining\Data_Central.mdb")
  5.         my_database.Execute "insert into Data_Central.Employee(UserID, EmployeeID, TodayDate, DOB,Title,Fname,Mname,Lname,Suffix, Address1,Address2,City,State,PostalCode,Country,Gender,MaritalStatus,HomePhone,MobilePhone,Fax,Email,LicenseNum,Day,Month,Year,County) Values('" & Text1(0).Text & "','" & Text1(1).Text & "' , '" & Text1(2).Text & "' , '" & Text1(3).Text & "','" & Text1(4).Text & "' , '" & Text1(5).Text & "' ,'" & Text1(6).Text & "' ,'" & Text1(7).Text & "' ,'" & Text1(8).Text & "' ,'" & Text1(9).Text & "' ,'" & Text1(10).Text & "' ,'" & Text1(11).Text & "' ,'" & Text1(12).Text & "','" & Text1(13).Text & "' ,'" & Text1(14).Text & "' ,'" & Text1(15).Text & "' ,'" & Text1(16).Text & "' ,'" & Text1(17).Text & "' ,'" & Text1(18).Text & "' ,'" & Text1(19).Text & "' ,'" & Text1(20).Text & "' ,'" & Text1(21).Text & "' ,'" & Text1(22).Text & "','" & Text1(23).Text & "','" & Text1(24).Text & "','" & Text1(25).Text & "')"
  6.         my_database.Close ' close the database
  7.  
  8. End Sub
  9.  
You probably don't need all of the textboxes I have added...

Have fun:-)
Apr 4 '08 #3
debasisdas
8,127 Expert 4TB
If using adodb then try using this

create a connection object
open the connection
Expand|Select|Wrap|Line Numbers
  1. con.BeginTrans
  2. con.execute "your insert statment goes here"
  3. 'con.execute "your update statment goes here"  
  4. con.CommitTrans
  5.  
Apr 4 '08 #4
I wanted to view the table of sqlite database in a datagrid or Flexgrid of VB 6.
and allow datagrid for edit and update to the databae.
Here is my code...
But it showed all the table in a single row of flex grid :s




Option Explicit

'// SQL Lite dll declarations:

Private Declare Sub sqlite3_open Lib "SQLite3VB.dll" (ByVal filename As String, ByRef handle As Long)
Private Declare Sub sqlite3_close Lib "SQLite3VB.dll" (ByVal DB_Handle As Long)
Private Declare Function sqlite3_last_insert_rowid Lib "SQLite3VB.dll" (ByVal DB_Handle As Long) As Long
Private Declare Function sqlite3_changes Lib "SQLite3VB.dll" (ByVal DB_Handle As Long) As Long
Private Declare Function sqlite_get_table Lib "SQLite3VB.dll" (ByVal DB_Handle As Long, ByVal SQLString As String, ByRef errstr As String) As Variant()
Private Declare Function sqlite_libversion Lib "SQLite3VB.dll" () As String ' Now returns a BSTR

'// This function returns the number of rows from the last sql statement. Use this to ensure you have a valid array
Private Declare Function number_of_rows_from_last_call Lib "SQLite3VB.dll" () As Long




Private Sub Command1_Click()
Dim dbfile As String
Dim dbquery As String
Dim db As Long
Dim mvar As Variant
Dim mv1 As Variant
Dim errstr As String
Dim row As Long
Dim col As String
Dim mstr As String
Dim i As Long
Dim L1 As ListItem
Dim j As Long



dbfile = App.Path & "\jas.db"
dbquery = "select * from rec2"

If dbfile = "" Or dbquery = "" Then
MsgBox "Query not found:"
Else
sqlite3_open dbfile, db

If db > 0 Then
mvar = sqlite_get_table(db, dbquery, errstr)
row = number_of_rows_from_last_call
row = row + 1
lbl1.Caption = row
If row > 0 Then

For Each mv1 In mvar
mstr = mv1
col = mstr

If i < row Then
DataGrid1.TextMatrix(i, 1) = col
i = i + 1
End If
If i >= row Then

DataGrid1.TextMatrix(i, 2) = col

End If
Next

End If
End If

sqlite3_close db
End If

End Sub
Jul 4 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Hamed | last post by:
Hello I have employed as a developer in a software company that its team uses FoxPro / VB 6.0 / VC++ 6.0 as the developing tools and newly is going to migrate to VS.NET. There is a project...
0
by: sedefo | last post by:
I ran into this Microsoft Patterns & Practices Enterprise Library while i was researching how i can write a database independent data access layer. In my company we already use Data Access...
12
by: Manolis | last post by:
Hi, I was wondering if there is any way to make two objects of the same class to be able to access each other's private data, like this: class A { public: void access( const A& a )...
32
by: Neil Ginsberg | last post by:
We're using SQL Server 7 with an Access 2000 MDB as a front end with ODBC linked tables. I recently created a new set of tables for the app, and users are complaining that unsaved data is being...
9
by: Tony Lee | last post by:
Some time a ago, on this newsgroup the following comments were made in recommending good references for Access (2003) >I used to recommend Dr. Rick Dobson's, "Programming Access <version>" for...
3
by: Lyle Fairfield | last post by:
In a recent thread there has been discussion about Data Access Pages. It has been suggested that they are not permitted on many or most secure sites. Perhaps, that it is so, although I know of no...
9
by: the_grove_man | last post by:
I guess my question can go in two directions. I create applications that run multiple queries against a database. Generally speaking in the past I have used a Data Control (calling it dat1)...
1
by: Johann Blake | last post by:
I am looking for a good solution on how to implement data access in an application so that there is a clean separation between the data access layer, the business layer and the GUI layer. I am...
20
by: TC | last post by:
I need an automated procedure to copy data from an Access table to a SQL Server table. Speed is important. What is the recommended technique? I can export the data from Access, copy it via FTP,...
6
by: Wesley Peace | last post by:
I hate to cross post, but I've gotten no answer yet on a problem I'm having with visual studio 2008. I've created a series of forms with controls to access a Access database tables. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.