vb.net数据集,vbnet数据库
VB.net怎么访问数据集?我是VS2019的。
可用ado.net访问。
在丽水等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供做网站、网站建设 网站设计制作按需开发,公司网站建设,企业网站建设,高端网站设计,营销型网站建设,成都外贸网站建设公司,丽水网站建设费用合理。
换电脑数据还在要求有服务器,要么是局域网内一台服务器,要么是公网服务器。
VB.NET数据集怎么排序?
给数据集排序?为什么不直接在SQL文里排序。。如果你逼不得已非要用数据集排序。。就得循环了,循环数据集,按照你的需求来做出排序,重新绑定到数据集里。。
vb.net的数据库连接
1·绑定数据源来进行连接
2.用代码连接
先到数据库建立一个数据库和相应的表
连接数据库的代码:
Dim str As String = "Data Source=服务器名;Initial Catalog=数据库名;Persist Security Info=True;User ID=;Password="
dim conn As SqlClient.SqlConnection
try
conn = New SqlClient.SqlConnection
conn.ConnectionString = str
conn.Open()
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
登录代码:Dim str As String = "Data Source=服务器名;Initial Catalog=数据库名;Persist Security Info=True;User ID=;Password="
dim conn As SqlClient.SqlConnection
conn = New SqlClient.SqlConnection
conn.ConnectionString = str
conn.Open()
sqlstr = "Select * From Amd Where AmdName='" TextBox1.Text "' And AmdPwd = '" TextBox2.Text "'"
Dim sqlcmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(sqlstr, conn)
Dim dr As SqlClient.SqlDataReader
dr = sqlcmd.ExecuteReader
If dr.Read = True Then '判断一条记录为真
kf.Show() '显示下个窗体
Me.Hide() ’隐藏当前窗体
Else
MessageBox.Show("输入信息有误!", "提示")
TextBox1.Text = ""
TextBox2.Text = ""
End If
vb.net读取Access数据库的方法
建立数据集,绑定到窗口。不会的话,把要用的表从数据集拖到窗口,再删除就行了
提取方法
数据及名称.表格名称.rows(2).item(3).tostring 就是了
vb.net数据库操作
参考一下下面这段代码就可以了。
Imports System.Data
'引入数据库操作类命名空间
Imports System.Data.OleDb
'引入ADO.NET操作命名空间
Public Class FrmModifystInfo
Inherits System.Windows.Forms.Form
Public ADOcmd As OleDbDataAdapter
Public ds As DataSet = New DataSet()
'建立DataSet对象
Public mytable As Data.DataTable
'建立表单对象
Public myrow As Data.DataRow
'建立数据行对象
Public rownumber As Integer
'定义一个整型变量来存放当前行数
Public SearchSQL As String
Public cmd As OleDbCommandBuilder
'======================================================
#Region " Windows 窗体设计器生成的代码 "
#End Region
'======================================================
Private Sub FrmModifystInfo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
'窗体的载入
TxtSID.Enabled = False
TxtName.Enabled = False
ComboSex.Enabled = False
TxtBornDate.Enabled = False
TxtClassno.Enabled = False
TxtRuDate.Enabled = False
TxtTel.Enabled = False
TxtAddress.Enabled = False
TxtComment.Enabled = False '设置信息为只读
Dim tablename As String = "student_Info "
SearchSQL = "select * from student_Info "
ExecuteSQL(SearchSQL, tablename) '打开数据库
ShowData() '显示记录
End Sub
Private Sub ShowData()
'在窗口中的textbox中显示数据
myrow = mytable.Rows.Item(rownumber)
TxtSID.Text = myrow.Item(0).ToString
TxtName.Text = myrow.Item(1).ToString
ComboSex.Text = myrow.Item(2).ToString
TxtBornDate.Text = Format(myrow.Item(3), "yyyy-MM-dd ")
TxtClassno.Text = myrow.Item(4).ToString
TxtTel.Text = myrow.Item(5).ToString
TxtRuDate.Text = Format(CDate(myrow.Item(6)), "yyyy-MM-dd ")
TxtAddress.Text = myrow.Item(7).ToString
TxtComment.Text = myrow.Item(8).ToString
End Sub
Private Sub BtFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtFirst.Click
'指向第一条数据
rownumber = 0
ShowData()
End Sub
Private Sub BtPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtPrev.Click
'指向上一条数据
BtNext.Enabled = True
rownumber = rownumber - 1
If rownumber 0 Then
rownumber = 0 '如果到达记录的首部,行号设为零
BtPrev.Enabled = False
End If
ShowData()
End Sub
Private Sub BtNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtNext.Click
'指向上一条数据
BtPrev.Enabled = True
rownumber = rownumber + 1
If rownumber mytable.Rows.Count - 1 Then
rownumber = mytable.Rows.Count - 1 '判断是否到达最后一条数据
BtNext.Enabled = False
End If
ShowData()
End Sub
Private Sub BtLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtLast.Click
'指向最后一条数据
rownumber = mytable.Rows.Count - 1
ShowData()
End Sub
Private Sub BtDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtDelete.Click
mytable.Rows.Item(rownumber).Delete() '删除记录
If MsgBox( "确定要删除改记录吗? ", MsgBoxStyle.OKCancel + vbExclamation, "警告 ") = MsgBoxResult.OK Then
cmd = New OleDbCommandBuilder(ADOcmd)
'使用自动生成的SQL语句
ADOcmd.Update(ds, "student_Info ")
BtNext.PerformClick()
End If
End Sub
Private Sub BtModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtModify.Click
TxtSID.Enabled = False '关键字段只读
TxtName.Enabled = True '可读写
ComboSex.Enabled = True
TxtBornDate.Enabled = True
TxtClassno.Enabled = True
TxtRuDate.Enabled = True
TxtTel.Enabled = True
TxtAddress.Enabled = True
TxtComment.Enabled = True
End Sub
Private Sub BtUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtUpdate.Click
If Not Testtxt(TxtName.Text) Then
MsgBox( "请输入姓名! ", vbOKOnly + vbExclamation, "警告 ")
TxtName.Focus()
Exit Sub
End If
If Not Testtxt(ComboSex.Text) Then
MsgBox( "请选择性别! ", vbOKOnly + vbExclamation, "警告 ")
ComboSex.Focus()
Exit Sub
End If
If Not Testtxt(TxtClassno.Text) Then
MsgBox( "请选择班号! ", vbOKOnly + vbExclamation, "警告 ")
TxtClassno.Focus()
Exit Sub
End If
If Not Testtxt(TxtTel.Text) Then
MsgBox( "请输入联系电话! ", vbOKOnly + vbExclamation, "警告 ")
TxtTel.Focus()
Exit Sub
End If
If Not Testtxt(TxtAddress.Text) Then
MsgBox( "请输入家庭住址! ", vbOKOnly + vbExclamation, "警告 ")
TxtAddress.Focus()
Exit Sub
End If
If Not IsNumeric(Trim(TxtSID.Text)) Then
MsgBox( "请输入数字学号! ", vbOKOnly + vbExclamation, "警告 ")
Exit Sub
TxtSID.Focus()
End If
If Not IsDate(TxtBornDate.Text) Then
MsgBox( "出生时间应输入日期格式(yyyy-mm-dd)! ", vbOKOnly + vbExclamation, "警告 ")
Exit Sub
TxtBornDate.Focus()
End If
If Not IsDate(TxtRuDate.Text) Then
MsgBox( "入校时间应输入日期格式(yyyy-mm-dd)! ", vbOKOnly + vbExclamation, "警告 ")
TxtRuDate.Focus()
Exit Sub
End If
myrow.Item(0) = Trim(TxtSID.Text)
myrow.Item(1) = Trim(TxtName.Text)
myrow.Item(2) = Trim(ComboSex.Text)
myrow.Item(3) = Trim(TxtBornDate.Text)
myrow.Item(4) = Trim(TxtClassno.Text)
myrow.Item(5) = Trim(TxtTel.Text)
myrow.Item(6) = Trim(TxtRuDate.Text)
myrow.Item(7) = Trim(TxtAddress.Text)
myrow.Item(8) = Trim(TxtComment.Text)
mytable.GetChanges()
cmd = New OleDbCommandBuilder(ADOcmd)
'使用自动生成的SQL语句
ADOcmd.Update(ds, "student_Info ")
'对数据库进行更新
MsgBox( "修改学籍信息成功! ", vbOKOnly + vbExclamation, "警告 ")
TxtName.Enabled = False
ComboSex.Enabled = False
TxtBornDate.Enabled = False
TxtClassno.Enabled = False
TxtRuDate.Enabled = False
TxtTel.Enabled = False
TxtAddress.Enabled = False
TxtComment.Enabled = False '重新设置信息为只读
End Sub
Private Sub BtCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtCancel.Click
TxtSID.Enabled = False
TxtName.Enabled = False
ComboSex.Enabled = False
TxtBornDate.Enabled = False
TxtClassno.Enabled = False
TxtRuDate.Enabled = False
TxtTel.Enabled = False
TxtAddress.Enabled = False
TxtComment.Enabled = False
End Sub
Public Function ExecuteSQL(ByVal SQL As String, ByVal table As String)
Try
'建立ADODataSetCommand对象
'数据库查询函数
ADOcmd = New OleDbDataAdapter(SQL, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\student.mdb ")
'建立ADODataSetCommand对象
ADOcmd.Fill(ds, table) '取得表单
mytable = ds.Tables.Item(0) '取得名为table的表
rownumber = 0 '设置为第一行
myrow = mytable.Rows.Item(rownumber)
'取得第一行数据
Catch
MsgBox(Err.Description)
End Try
End Function
End Class
vb.net从数据库读取信息填充treeview做成层次目录怎么做
给你一段我曾经写的代码,主要是生成TreeView的节点!有什么不懂的地方你就提!
Public Sub InitializeTreeView(ByVal strvXL As TreeView, ByVal vrsRecordTwo As DataSet)
Dim treBaseNodeOne As TreeNode
Dim treBaseNodeTwo As TreeNode
Dim strDWDM As String
m_rsRecordTwo = g_clsSybase.SelectSC_PD_SBCSB1()
'查找供电局信息
g_clsSybase.SelectRS_ZZJG_ZZJGDMB(m_rsRecordOne)
'添加根节点
Do While m_rsRecordOne.Read
strDWDM = m_rsRecordOne.GetString(0) '获取单位代码
treBaseNodeOne = New TreeNode
treBaseNodeOne.Text = m_rsRecordOne.GetString(1).Trim() '获取单位名称
treBaseNodeOne.Name = m_rsRecordOne.GetString(1)
treBaseNodeOne.Tag = ""
strvXL.Nodes.Add(treBaseNodeOne)
'添加树结构第二层
Dim drsTwo() As DataRow
drsTwo = m_rsRecordTwo.Tables(0).Select("SSDW='" strDWDM "' and SC__XLBM is null")
For Each dr As DataRow In drsTwo
treBaseNodeTwo = New TreeNode
treBaseNodeTwo.Text = dr.Item("XLMC").ToString.Trim
treBaseNodeTwo.Name = dr.Item("XLMC")
treBaseNodeTwo.Tag = dr.Item("XLBM")
treBaseNodeOne.Nodes.Add(treBaseNodeTwo)
Next
Loop
m_rsRecordOne.Close()
End Sub
当前名称:vb.net数据集,vbnet数据库
分享地址:http://scyanting.com/article/hedige.html