Click here to Skip to main content
15,885,981 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Imports System.Data.OleDb
Public Class WF
Dim cnn As New OleDb.OleDbConnection

Private Sub RefreshData()
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If

Dim da As New OleDb.OleDbDataAdapter(" SELECT Husband as [Husband], Wife as [Wife], Husband's Birthday as [Husband's Birthday], Husband's Age as [Husband's Age], Wife's Birthday as [Wife's Birthday], Wife's Age as [Wife's Age], Husband's Mother as [Husband's Mother], Husband's Father as [Husband's Father], Wife's Father as [Wife's Father], Wife's Mother as [Wife's Mother], Date of Wedding as [Date of Wedding] FROM Wedding ", cnn)

Dim dt As New DataTable

da.Fill(dt)==> this is the error
dgv1.DataSource = dt
cnn.Close()
End Sub

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim cmd As New OleDb.OleDbCommand

If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If

cmd.Connection = cnn
cmd.CommandText = " INSERT INTO Wedding ([Husband], [Wife], [Husband's Birthday], [Husband's Age], [Wife's Birthday],[Wife's Age], [Husband's Mother], [Husband's Father], [Wife's Father], [Wife's Mother], [Date of Wedding]) " & _
" VALUES('" & txtHN.Text & "','" & txtWN.Text & "','" & txtHBD.Text & "','" & txtHA.Text & "','" & txtWBD.Text & "','" & txtWA.Text & "','" & txtHM.Text & "','" & txtHF.Text & "','" & txtWF.Text & "','" & txtWM.Text & "','" & txtDoW.Text & "')"
cmd.ExecuteNonQuery()

RefreshData()

cnn.Close()

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cnn = New OleDb.OleDbConnection
Dim sql_query As String
sql_query = "SELECT * FROM Wedding"

cnn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source = " & Application.StartupPath & "\Churh.mdb"

End Sub
End Class
Posted
Comments
Ch Smrutiranjan 19-Oct-14 1:28am    
Some thing wrong with your query.(Syntax). Pls check again that and if possible run that query in DB and check.

or this can be due tonyou use keyword as your table name or field name. For instance Date,Catalog etc are keywords.

Ch Smrutiranjan 19-Oct-14 1:31am    
Just put [reserved key word] in this format and chk.

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