vb.net数据库应用 vb数据库操作实例( 五 )


End Function
@#更新表UpdateTableName所指定的行
Public Shadows Sub Update()
Dim SetField As String
Dim i As Int16
For i = 1 To FieldCount - 1
SetField = UpdateTableFieldNames.Columns(i).ColumnName"="ObjFields(i)
UpdateField(SetField)
Next
End Sub
Public Sub UpdateField(ByVal SetField As String)
Dim StrSQL As String
StrSQL = "select * from "UpdateTableName" where fSystemID= "SystemID
DB.Update(StrSQL, SetField)
End Sub
@#填充网络数据
Public Overloads Sub FillGrid(ByVal GridName As DataGrid)
GridName.DataSource = UpdateDataTable
End Sub
@#把数据网格的当前行数据定写入到输入控件中
Public Sub DataGridToText(ByVal frm As Form)
Dim RowIndex, i As Int16
Dim value
Dim obj As Control
Dim DataGrid As New DataGrid()
If FieldCount = 0 Then Exit Sub
For Each obj In frm.Controls
If obj.GetType.Name = "DataGrid" Then
DataGrid = obj
Exit For
End If
Next
RowIndex = DataGrid.CurrentRowIndex
For i = 1 To FieldCount - 1
value = https://www.04ip.com/post/DataGrid.Item(RowIndex, i)
If IsDBNull(value) = True Then
valuehttps://www.04ip.com/post/= ""
End If
For Each obj In frm.Controls @#
If obj.TabIndex = i Then
obj.Text = value
Exit For
End If
Next
Next
End Sub
vb.net 怎么操作数据库如果楼主熟悉VB6vb.net数据库应用,可以直接在项目中添加ADODBvb.net数据库应用的Com引用,这样你就可以像VB6那样操作数据库vb.net数据库应用了!
另外
.NET
Framework中连接数据库要用到ADO.NET 。如果要操作Access数据库,要用到System.Data.OleDb命名空间下vb.net数据库应用的许多类 。
比如按楼主所说,“vb.net数据库应用我想在textbox1中显示表一中【一些数据】字段下的第一个内容”:
'首先导入命名空间
Imports
System.Data
Imports
System.Data.OleDb
'然后在某一个事件处理程序中写:
Dim
conn
As
New
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=数据库.accdb;Jet
OLEDB:Database
Password=MyDbPassword")
Dim
command
As
New
OleDbCommand("Select
*
From
数据表",
conn)
conn.Open()
'打开数据库连接
Dim
reader
As
OleDbDataReader
=
command.ExecuteReader()
'执行SQL语句 , 返回OleDbDataReader
对象
Do
While
reader.Read()
'读取一条数据
textbox1.Text
+=
reader("一些数据")
VbCrLf
Loop
reader.Close()
'关闭OleDbDataReader
conn.Close()
'关闭连接
vb.net 中如何使用SQL语句查询数据库中的数据1、首先打开Visual Studio 2008代码窗口,添加引用 。
2、输入以下代码:Public conn1As SqlConnection = New SqlConnection。
3、声明关键字 Public;(因为是全局变量,所以用Public 来声明) 。
4、如果SQL 数据库就在本机,则用以下代码连接 。
5、如果代码太长,影响可读性,可以用空格加"_"后,回车换行即可 。
使用VB.net实现sql数据库的备份与恢复代码 Private Sub Button _Click(ByVal sender As System Object ByVal e As System EventArgs) Handles Button Click 备份数据库 BACKUP DATABASE Test TO DISK= C:\Backup WITH Format Dim cn As SqlConnection Dim cm As SqlCommand cn = getDB() cm = New SqlCommand( BACKUP DATABASE JXbase TO DISK= C:\Backup WITH Format cn) cn Open() cm ExecuteNonQuery() MsgBox( 备份成功 ) cn Close()
End Sub
恢复 Private Sub Button _Click(ByVal sender As System Object ByVal e As System EventArgs) Handles Button Click Dim cn As New SqlConnection Dim cn As New SqlConnection Dim mydr As SqlDataReader Dim str As String

推荐阅读