Sunday, November 14, 2010

How do i insert records in an access database using vb 6?

the values sum1, sum2, and total are to be inserted in a table with fields 'total exercises', 'total exams', and 'final grade' respectively.



I tried assigning data sources and fields to the labels i made where these results are supposed to be displayed, and then I used the command



data3.recordset.update



it didn't work T-T... please help me... if possible, please provide the code for vb 6 thanks so much!How do i insert records in an access database using vb 6?
Dim OleDbConn1 As OleDbConnection

Dim ConStr As String = ';Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydb.mdb;User Id=admin;Password=;';

'Here my access database file is in c:\, replace it with ur file location

Dim SqlStr As String = ';INSERT INTO my_Table VALUES('; %26amp; Val(sum1) %26amp; ';,'; %26amp; Val(sum2) %26amp; ';,'; %26amp; Val(total) %26amp; ';)';

'The Sql string is very important and take great care to design it. If the data type in the table is Varchar, use single

'Quotes at the two ends of the variable... and if the datatype is integer do not use any single quote and use

'val(variable) to get the value of the text inside.

Dim Cmd As New OleDbCommand(SqlStr,OleDbCon1)

OleDbCon1.Open()

Cmd.ExecuteNonQuery() 'This command will insert the data.

OleDbCon1.Close()

No comments:

Post a Comment