Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!

I am trying to connect to MS access with vb.net using following steps:

1. Select "TOOL" from the menubar
2. Select "connect to database"
3. Enter the path of the database and click TEST CONNECTION. It will display the message "TEST CONNECTION SUCCESSFUL"

After that, I am writing some code in my form where I want to perform the insert query. The code is:

VB
Imports System.Data.OleDb

Public Class Item_Info
    Dim cn As OleDbConnection
    Dim cmd As OleDbCommand
    Dim da As OleDbDataAdapter
    Dim dr As OleDbDataReader
    Dim str As String
    Dim icount As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        cn = "here i am putting my database path.. connectionstring"
        cn.Open()
        str = "insert into Item_Master values('" & txtName.Text & "','" & txtCode.Text & "')"
        cmd = New OleDbCommand(str, cn)
        cmd.ExecuteNonQuery()
        cn.Close()

    End Sub
End Class


But when I run this form it doesn't create any output. Nor does it give any errors...... I don't understand what the problem is.
Please help me!
Posted
Updated 29-Jun-10 3:44am
v4

Maybe something like :
"insert into Item_Master (Name, Code) values('" & txtName.Text & "','" & txtCode.Text & "')"


Cheers
 
Share this answer
 
Comments
William Winner 29-Jun-10 17:50pm    
If there are only two columns, his code will work fine.
tiggerc 30-Jun-10 9:23am    
Reason for my vote of 5
SQL syntax,
The only problem that I see could be your connection string. Though, you should get an error if that was the case.

And did you make sure that you did cn = New OldDbConnection()?

And is Item_Master in the database?

Simple questions, but from what you've provided, I can't see any other source of problems.

Also, check what cmd.ExecuteNonQuery() returns. It should return 1 if it was successful.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900