Imports?System.Data.OleDb??
創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務,包含不限于成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、銀海網(wǎng)絡推廣、重慶小程序開發(fā)、銀海網(wǎng)絡營銷、銀海企業(yè)策劃、銀海品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)為所有大學生創(chuàng)業(yè)者提供銀海建站搭建服務,24小時服務熱線:028-86922220,官方網(wǎng)址:m.newbst.com
Public?Class?Form1??
Dim?cn?As?OleDbConnection??
Dim?da?As?OleDbDataAdapter??
Dim?ds?As?DataSet??
Private?Sub?Form1_Load(sender?As?Object,?e?As?EventArgs)?Handles?MyBase.Load??
Dim?cnStr?As?String?=?"Provider=Microsoft.Jet.OLEDB.4.0;Data?Source=D:\persons.mdb;Persist?Security?Info=False"??
cn?=?New?OleDbConnection(cnStr)??
Dim?sql?As?String?=?"select?*?from?grade"??
da?=?New?OleDbDataAdapter(sql,?cn)??
ds?=?New?DataSet??
da.Fill(ds,?"grade")??
DataGridView1.DataSource?=?ds.Tables(0)??
End?Sub??
End?Class
解釋:
?Dim cnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\persons.mdb;Persist Security Info=False" ?
這段是創(chuàng)建鏈接字符串,你可以根據(jù)自己數(shù)據(jù)庫實際存放位置進行修改
Dim sql As String = "select * from grade"
這是數(shù)據(jù)庫查詢語句,你可以根據(jù)實際情況修改下
Dim?sql?As?String?=?"select?*?from?grade"??
da?=?New?OleDbDataAdapter(sql,?cn)??
ds?=?New?DataSet??
da.Fill(ds,?"grade")??
DataGridView1.DataSource?=?ds.Tables(0)
這是執(zhí)行查詢語句后,將查詢的結(jié)果存入datagridview中
給你寫個例子,不明白,再問!!
'引入OLEDB命令空間
Imports System.Data.OleDb
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
'定義一個OLEDB連接并實例化它
Dim con As New OleDbConnection
'定義一個OLEDB命令并實例化他
Dim cmd As New OleDbCommand
'定義一個OLEDBReader方法來讀取數(shù)據(jù)庫
Dim dr As OleDbDataReader
'初始化con的連接屬性,使用OLEDB模式,數(shù)據(jù)源為:你指定下路徑,我的是在D盤
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\dataSample.mdb"
'打開OLEDB數(shù)據(jù)連接
con.Open()
'初始化OLEDB命令的連接屬性為con,這個需要你理解下
cmd.Connection = con
'初始化OLEDB命令的語句 就是查詢 什么字段從什么表 條件是ID等于你在t1中輸入的內(nèi)容
cmd.CommandText = "select keyss from table1 where ID=" t1.Text ""
'執(zhí)行OLEDB命令以ExecuteReader()方式,并返回一個OLEDBReader,賦值給dr
dr = cmd.ExecuteReader()
'判斷下dr中是否有數(shù)據(jù)。如果有就把第一個值賦值給t2的值
If dr.Read() Then
t2.Text = dr(0)
End If
'完成后關(guān)閉dr.con等釋放資源
dr.Close()
con.Close()
End Sub
End Class
建立數(shù)據(jù)集,綁定到窗口。不會的話,把要用的表從數(shù)據(jù)集拖到窗口,再刪除就行了
提取方法
數(shù)據(jù)及名稱.表格名稱.rows(2).item(3).tostring 就是了
mports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data.OleDb
Imports System.Data
Public Class Form1
Inherits Form
Private components As System.ComponentModel.Container = Nothing
Private WithEvents lastrec As Button
Private WithEvents nextrec As Button
Private WithEvents previousrec As Button
Private WithEvents firstrec As Button
Private t_books As TextBox
Private t_nl As TextBox
Private t_xb As TextBox
Private t_xm As TextBox
Private t_id As TextBox
Private l_books As Label
Private l_nl As Label
Private l_xb As Label
Private l_xm As Label
Private l_id As Label
Private label1 As Label
Private myDataSet As DataSet
Private WithEvents button1 As Button
Private WithEvents button2 As Button
Private WithEvents button3 As Button
Private WithEvents button4 As Button
Private myBind As BindingManagerBase
Public Sub New ( )
MyBase.New ( )
GetConnected ( )
InitializeComponent ( )
End Sub
'清除在程序中使用過的資源
Protected Overloads Overrides Sub Dispose (ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose ( )
End If
End If
MyBase.Dispose ( disposing )
End Sub
Public Sub GetConnected ( )
'創(chuàng)建一個數(shù)據(jù)連接
Dim strCon As String = " Provider = Microsoft.Jet.OLEDB.4.0 ;
Data Source = db.mdb "
Dim myConn As OleDbConnection = New OleDbConnection ( )
myConn.ConnectionString = strCon
Dim strCom As String = " SELECT * FROM person "
'創(chuàng)建一個 DataSet
myDataSet = New DataSet ( )
myConn.Open ( )
'通過OleDbDataAdapter對象得到一個數(shù)據(jù)集
Dim myCommand As OleDbDataAdapter = New OleDbDataAdapter
( strCom , myConn )
'把Dataset綁定books數(shù)據(jù)表
myCommand.Fill ( myDataSet , "person" )
'關(guān)閉此數(shù)據(jù)連接
myConn.Close ( )
End Sub
'插入數(shù)據(jù)記錄操作代碼
Private Sub button2_Click (ByVal sender As Object , _
ByVal e As System.EventArgs) Handles button2.Click
'判斷所有字段是否添完,添完則執(zhí)行,反之彈出提示
If ( t_id.Text "" And t_xm.Text ""
And t_xb.Text "" And t_nl.Text ""
And t_books.Text "" ) Then
Dim myConn1 As String = " Provider = Microsoft.Jet.OLEDB.4.0 ;
Data Source = db.mdb"
Dim myConn As OleDbConnection = New OleDbConnection ( myConn1 )
myConn.Open ( )
Dim strInsert As String = " INSERT INTO person ( id , xm , xb , nl
, zip ) VALUES ( " _
t_id.Text + " , '" _
t_xm.Text + "' , '" _
t_xb.Text + "' , " _
t_nl.Text + " , " _
t_books.Text + ")"
Dim inst As OleDbCommand = New OleDbCommand ( strInsert , myConn )
inst.ExecuteNonQuery ( )
myConn.Close ( )
myDataSet.Tables ( "person" ).Rows ( myBind.Position ).BeginEdit ( )
myDataSet.Tables ( "person" ).Rows ( myBind.Position ).EndEdit ( )
myDataSet.Tables ( "person" ).AcceptChanges ( )
Else
MessageBox.Show ( "必須填滿所有字段值!" , "錯誤!" )
End If
End Sub
分享標題:vbnetascc的簡單介紹
轉(zhuǎn)載源于:http://m.newbst.com/article22/doghejc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、用戶體驗、云服務器、定制開發(fā)、電子商務、網(wǎng)頁設(shè)計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)