Imports System.Data.SqlClient
Public Class Form1
Dim conn As SqlConnection
Dim da As SqlDataAdapter
Dim ds As DataSet '必须加“NEW”关键字
Dim dt As DataTable
Private Function GetConnection() As SqlConnection
Return New SqlConnection(My.Settings.SalesConnectionString)
End Function
Private Sub DisplayData1(ByVal str As String, ByVal datagridview1 As DataGridView) '用DataReader对象
datagridView1.DataSource = Nothing
conn = GetConnection()
conn.Open()
Dim comm As New SqlCommand(str, conn)
Dim dr As SqlDataReader = comm.ExecuteReader
Dim dt As New DataTable
dt.Load(dr)
conn.Close()
DataGridView1.DataSource = dt
End Sub
Private Sub DisplayData2(ByVal str As String, ByVal datagridview1 As DataGridView) '用DataSet对象和Adapter的Fill方法
DataGridView1.DataSource = Nothing
conn = GetConnection()
conn.Open()
da = New SqlDataAdapter(str, conn)
da.Fill(ds, "dt")
conn.Close()
DataGridView1.DataSource = ds.Tables("dt")
End Sub
Private Sub DisplayData3(ByVal str As String, ByVal datagridview1 As DataGridView) '用DataSet对象和Adapter的Fill方法
DataGridView1.DataSource = Nothing
conn = GetConnection()
Dim comm As New SqlCommand(str, conn)
da = New SqlDataAdapter()
da.SelectCommand = comm
conn.Open()
ds = New DataSe
数据库开发025使用DataView对象进行查询
最新推荐文章于 2021-05-22 15:52:07 发布
本文详细介绍了在数据库开发中如何利用DataView对象进行高效查询,探讨了其筛选、排序和分页功能的实现,为数据库操作提供灵活的数据检索方案。
摘要由CSDN通过智能技术生成