Folks: I got rid of the error now.. this is my code..pls take a look at the button1_click function! i dont see any data being entered into my database. :( Your guidance will be very helpful!


Thanks,
Kukki.

Public Class Form2

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim objcmd As New Data.OleDb.OleDbCommand

Dim con As OleDb.OleDbConnection = New OleDb.OleDbConnection("provider=microsoft.jet.OLEDB.4.0; data source=C:\Documents and Settings\bashkark\Desktop\USERS.mdb")

Button1.BackColor = System.Drawing.Color.CornflowerBlue

Button2.BackColor = System.Drawing.Color.Bisque

End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

End

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


Dim con As New OleDb.OleDbConnection

Dim cmd As OleDb.OleDbCommand

Dim icount As Integer

Dim str As String

Try

con = New OleDb.OleDbConnection("provider=microsoft.jet.OLEDB.4.0; data source=C:\Documents and Settings\bashkark\Desktop\USERS.mdb")

con.Open()

str = "insert into table1 values('" & TextBox1.Text & "', '" & TextBox2.Text & "', '" & TextBox3.Text & "', '" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "', '" & TextBox7.Text & "','" & TextBox8.Text & "', '" & TextBox9.Text & "','" & TextBox10.Text & "','" & TextBox11.Text & "','" & TextBox12.Text & "','" & TextBox13.Text & "','" & TextBox14.Text & "','" & TextBox15.Text & "','" & TextBox16.Text & "','" & TextBox17.Text & "')"

cmd = New OleDb.OleDbCommand(str, con)

icount = cmd.ExecuteNonQuery

MessageBox.Show(icount)


Catch

End Try

con.Close()

End Sub

End Class

I think the Connection string is Case Sensitive. Please try this ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND_RW.MDB")

Replace the data source path with the path to your file.

Thanks sierra info..i got it right.. this is my new problem..i want to check a box and connect it to the SQL query..pls help me understand where I am going wrong !

Thanks
Kavitha.

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

Dim con As New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\bashkark\Desktop\Copy of USERS.mdb")

con.Open()

Dim cmd1 As New OleDbCommand

If (CheckBox1.Checked = True) Then

cmd1 = New OleDbCommand("select * from table1 where MECH='X'")

Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd1)

Try

Dim ds As DataSet = New DataSet()

ds.Tables.Add("table1")

da.Fill(ds, "table1")

DataGridView1.DataSource = ds.Tables("table1").DefaultView

Finally

con.Close()

cmd1 = Nothing

da.Dispose()

con.Dispose()

End Try

End If
End Sub

I think the Connection string is Case Sensitive. Please try this ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND_RW.MDB")

Replace the data source path with the path to your file.

Hi,
Since you are using an Adapter- follow these steps:
1. No need to open and Close the Con-comment those lines. The Adapter opens and closes the Connection when you use the Fill,Update method.

2. No need for this--ds.Tables.Add("table1")
the Fill method creates the table automatically - in your case - with the name you have specified - "table1".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.