0

please can anyone tell the wrong of this attached project * the data appears as empty in the grid! * dgv.rows.add(5) also don't work!

https://www.dropbox.com/s/s96dw694wc744od/WindowsApplication2.rar?dl=0

Imports ADODB
Imports System.Data.OleDb

Public Class Form1
Dim Cntemp As New ADODB.Connection
Dim Rstemp As New ADODB.Recordset
Dim Dataset1 As New DataSet
Dim DataAdapter1 As New OleDbDataAdapter

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As     System.EventArgs) Handles MyBase.Load
    dt.Value = Today

    Cntemp.Open("Provider=Microsoft.ace.OLEDB.12.0; Data Source=" &  Application.StartupPath & "\vbdata.accdb")
    Rstemp.Open("Select * From tbltemp", Cntemp, 1, 2)

    DataAdapter1.Fill(Dataset1, Rstemp, "tbltemp")
    dgv.DataSource = Dataset1.Tables(0)

    dgv.Rows.Add(5)

 End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    If Cntemp.State = 1 Then Cntemp.Close()

    Cntemp.Open("Provider=Microsoft.ace.OLEDB.12.0; Data Source=" & Application.StartupPath & "\vbdata.accdb")

    Dim totalprc, u, m As Integer
    u = uprc.Text
    m = mnum.Text
    totalprc = u * m

    Cntemp.Execute("insert into tbltemp (mname,uprice,mnum,tprice) " _
                   & " values('" _
                   & mnm.Text _
                   & "','" _
                   & uprc.Text _
                   & "','" _
                   & mnum.Text _
                   & "','" _
                   & totalprc & "')")

    Dataset1.Clear()
    Rstemp.Open("Select * From tbltemp", Cntemp, CursorTypeEnum.adOpenDynamic, LockTypeEnum.adLockOptimistic)

    DataAdapter1.Fill(Dataset1, Rstemp, "tbltemp")
    dgv.DataSource = Dataset1.Tables(0)
    dgv.Refresh()
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
    Application.Exit()
End Sub
End Class

1 Answers1

0

Try this with your form1 load event:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dt.Value = Today

        Cntemp.Open("Provider=Microsoft.ace.OLEDB.12.0; Data Source=" & Application.StartupPath & "\vbdata.accdb")
        Rstemp.Open("Select * From tbltemp", Cntemp, 1, 2)

        If Not Rstemp.EOF Then
            DataAdapter1.Fill(Dataset1, Rstemp, "tbltemp")
            dgv.DataSource = Dataset1.Tables(0)
        End If
    End Sub

And delete all your created columns in your DataGridView objects from your designer. I would highly suggest you bind your datagridview with a source rather than you use legacy ADODB.

Output: enter image description here

Amen Jlili
  • 1,884
  • 4
  • 28
  • 51
  • JLILI Aman, thank you for interesting! but (dgv.rows.add(10)) still not working.....and may you give more details about bind DGV with source rather than legacy ADODB? – Bass Alfan Feb 17 '15 at 05:27