需要以VB形式从访问表中读取数据 [英] Need to read the data from Access Table in VB Form

查看:194
本文介绍了需要以VB形式从访问表中读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,
我正在开发一个VB应用程序,该应用程序具有将数据读写到Access表中的功能.我正在完成写部分,如下所述.现在,我需要每60秒从Access Table读取数据到GridView.
这是用于将数据写入Access的代码.

Hai All,
I am developing one VB Application whose has Read&write the data into Access table. and i am completing the write section as mention as below. Now i need to read the data from Access Table to GridView for every 60 sec.
This is the code iam used to write the data into Access.

Dim cnnOLEDB As New OleDbConnection
    Dim cmdOLEDB As New OleDbCommand
    Dim cmdInsert As New OleDbCommand
    Dim cmdUpdate As New OleDbCommand
    Dim cmdDelete As New OleDbCommand
    Dim adpOLEDB As New OleDbDataAdapter
    Dim strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\SMSDB.mdb"





cmdInsert.CommandText = "INSERT INTO SMSDATA1DB (Start_Of_Packet, Packet_Identifier) VALUES ('" & STX1 & "', '" & STX2 & "')"
        MsgBox(cmdInsert.CommandText)
        cmdInsert.CommandType = CommandType.Text
        cmdInsert.Connection = cnnOLEDB
        cmdInsert.ExecuteNonQuery()
        cmdInsert.Dispose()





Private Sub DataPreview_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cnnOLEDB.ConnectionString = strConnectionString
        cnnOLEDB.Open()
End Sub




任何机构都可以帮助我.........




Any Body Help me.........

推荐答案

Dim dt1 As New DataTable()
    dt1.Clear()
    Dim adp As New OleDb.OleDbDataAdapter("SELECT * FROM SMSDATA1DB", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Environment.CurrentDirectory & "\SMSDB.mdb")
    adp.Fill(dt1)
    adp.Dispose()
    DataGridView1.DataSource = dt1




使用此代码检索数据表单访问表.... :)这是改进的解决方案,使用此.....:)




Use this code to retrieve data form access table....:) This is Improved solution use this.....:)


这篇关于需要以VB形式从访问表中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆