快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

关于vb.net数据库实例的信息

求VB.NET2010连接MDB数据库后,添加、修改和删除等写法示例

引用 Microsoft ActiveX Data Objects 2.8 Library

站在用户的角度思考问题,与客户深入沟通,找到永昌网站设计与永昌网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站制作、做网站、企业官网、英文网站、手机端网站、网站推广、域名申请、网页空间、企业邮箱。业务覆盖永昌地区。

或者加入microsoft ado data control

定义数据库连接

Dim Cnn As New ADODB.Connection

定义操作记录

Dim Res As New ADODB.Recordset

开始使用

If Res.State = 1 Then Res.Close

Res.CursorLocation = adUseClient

Res.Open "SELECT * From 发票表", Cnn, adOpenDynamic, adLockReadOnly

删除用res.Delete

添加用res.AddNew

res.Fields("序号") = Trim(Res.Fields("序号"))

...

res.Update

更新用Res.Update "序号", 111

列:

'写入产品信息

Sub WriteFP()

'On Error Resume Next

Dim SyBaseRes As New ADODB.Recordset

PB.value = 0

Res.Open "SELECT Count(*) From ICSaleEntry INNER JOIN t_Item ON ICSaleEntry.FItemID = t_Item.FItemID INNER JOIN t_MeasureUnit ON ICSaleEntry.FUnitID = t_MeasureUnit.FMeasureUnitID", SQLServer, adOpenDynamic, adLockReadOnly

Text2.Text = "当前共 " Val(Res.Fields(0)) "条数据"

PB.Max = Val(Res.Fields(0))

If Res.State = 1 Then Res.Close

Res.Open "SELECT ICSaleEntry.FDetailID AS 序号,ICSaleEntry.FInterID AS 物料编号, t_Item.FName AS 产品名称,ICSaleEntry.FAuxPrice AS 单价, ICSaleEntry.FAuxQty AS 数量,ICSaleEntry.FAmount AS 原币, ICSaleEntry.FStdAmount AS 本币,t_MeasureUnit.FName AS 单位 FROM ICSaleEntry INNER JOIN t_Item ON ICSaleEntry.FItemID = t_Item.FItemID INNER JOIN t_MeasureUnit ON ICSaleEntry.FUnitID = t_MeasureUnit.FMeasureUnitID", SQLServer, adOpenDynamic, adLockReadOnly

Do While Not Res.EOF

If SyBaseRes.State = 1 Then SyBaseRes.Close

SyBaseRes.Open "select * from 物料表 where 序号='" Res.Fields("序号") "'", Cnn, adOpenDynamic, adLockOptimistic

If SyBaseRes.EOF Then

Text2.Text = Text2.Text + vbCrLf + "正在添加: " Trim(Res.Fields("序号"))

SyBaseRes.AddNew

SyBaseRes.Fields("序号") = Trim(Res.Fields("序号"))

SyBaseRes.Fields("产品编号") = Trim(Res.Fields("物料编号"))

SyBaseRes.Fields("产品名称") = Trim(Res.Fields("产品名称"))

SyBaseRes.Fields("单价") = Trim(Res.Fields("单价"))

SyBaseRes.Fields("数量") = Trim(Res.Fields("数量"))

SyBaseRes.Fields("原币") = Trim(Res.Fields("原币"))

SyBaseRes.Fields("本币") = Trim(Res.Fields("本币"))

SyBaseRes.Fields("单位") = Trim(Res.Fields("单位"))

SyBaseRes.Fields("数据库名") = Trim(Text1.Text)

SyBaseRes.Update

Else

Text2.Text = Text2.Text + vbCrLf + "正在更新: " Trim(Res.Fields("序号"))

SyBaseRes.Update "序号", Trim(Res.Fields("序号"))

SyBaseRes.Update "产品编号", Trim(Res.Fields("物料编号"))

SyBaseRes.Update "产品名称", Trim(Res.Fields("产品名称"))

SyBaseRes.Update "单价", Trim(Res.Fields("单价"))

SyBaseRes.Update "数量", Trim(Res.Fields("数量"))

SyBaseRes.Update "原币", Trim(Res.Fields("原币"))

SyBaseRes.Update "本币", Trim(Res.Fields("本币"))

SyBaseRes.Update "单位", Trim(Res.Fields("单位"))

SyBaseRes.Update "数据库名", Trim(Text1.Text)

End If

PB.value = PB.value + 1

Res.MoveNext

DoEvents

Loop

If SyBaseRes.State = 1 Then SyBaseRes.Close

Set SyBaseRes = Nothing

End Sub

网络希望不要用ACCESS用ASA(就是sybase那个太强了)

请各位大侠给出用VB.NET连接oracle数据库并执行sql查询语句的代码示例,谢谢!!

Dim OraSession As Object '会话对象

Dim OraDatabase As Object '数据库对象

Dim OraDynaset As Object'动态集对象

Dim OraDatabase As Object’字段集对象

Set OraSession =CreateObject("OracleInProcServer.XOraSession")

Set OraDatabase=OraSession.CreateDatabase

("Demo","scott/tiger",0)'建立数据库连接

Set OraDynaset=OraDatabase.CreateDynaset("select*from

student",0)'初始化动态集对象

’添加记录

'Begin an AddNew

OraDynaset.DbAddNew

OraDynaset.Fields("ID").value="1000"

’ID为列名

OraDynaset.DbUpdate'更新数据到表

’删除

OraDynaset.DbDelete

'修改

OraDynaset.DbEdit

OraDynaset.Fields("ID").value="101210"

OraDynaset.DbUpdate

求一个用VB.net操作access数据库的例程

Imports System

Imports 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 ( )

'创建一个数据连接

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 "

'创建一个 DataSet

myDataSet = New DataSet ( )

myConn.Open ( )

'通过OleDbDataAdapter对象得到一个数据集

Dim myCommand As OleDbDataAdapter = New OleDbDataAdapter

( strCom , myConn )

'把Dataset绑定books数据表

myCommand.Fill ( myDataSet , "person" )

'关闭此数据连接

myConn.Close ( )

End Sub

'插入数据记录操作代码

Private Sub button2_Click (ByVal sender As Object , _

ByVal e As System.EventArgs) Handles button2.Click

'判断所有字段是否添完,添完则执行,反之弹出提示

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


当前名称:关于vb.net数据库实例的信息
分享网址:http://6mz.cn/article/docsecc.html

其他资讯