小弟初来乍到 最后一步

panzedong 2007-06-14 03:32:50
想做个查询 通过选择已知条件 来把整个表都显示出来
...全文
171 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ny-6000 2007-06-15
  • 打赏
  • 举报
回复
也来学习一下啦
mvpme82 2007-06-15
  • 打赏
  • 举报
回复
什么跟什么啊?
说得好含糊,就SQL语句呗
joeandlily 2007-06-14
  • 打赏
  • 举报
回复
你的意思是:拼动态SQL文?
snto 2007-06-14
  • 打赏
  • 举报
回复
代码有点大,看看吧:


Imports System.Data
Imports System.Data.OleDb

Public Class Form1



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim aa As New DataSet
'Dim bb As OleDbDataReader
Dim conn As New DataControl
conn.ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\test.mdb"
conn.Open()
aa = conn.Execute("select * from iuser", DataControl.ExecuteType.DataSet)
'bb = conn.Execute("select * from iuser", DataControl.ExecuteType.DataReader)
DataGridView1.DataSource = aa.Tables(0)
'DataGridView1.DataSource = bb
'DataGridView1.Columns.Add("haha", "haha")
'While bb.Read
'DataGridView1.Rows.Add(bb(0).ToString)
'End While
conn.Close()


Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class

Public Class DataControl
Private Conn As OleDbConnection
Private iConnstr As String
Private Cmd As OleDbCommand
Private DR As OleDbDataReader
Private DA As OleDbDataAdapter
Private DS As DataSet

Public Enum ExecuteType
DataReader = 0
DataSet = 1
End Enum

Public Sub New()
iConnstr = ""
Conn = New OleDbConnection()
End Sub

Public Sub Open()
Open(iConnstr)
End Sub

Public Sub Open(ByVal Connstr As String)
iConnstr = Connstr
If iConnstr.Trim = "" Then
Throw New Exception("连接字符串为空!")
End If
Try
Conn = New OleDbConnection(iConnstr)
Conn.Open()
Catch ex As Exception
Throw ex
End Try
End Sub

Public Function Execute(ByVal sql As String) As OleDbDataReader
Return Execute(sql, ExecuteType.DataReader)
End Function

Public Function Execute(ByVal sql As String, ByVal type As ExecuteType)
If Not Conn.State = ConnectionState.Open Then
Throw New Exception("未建立连接!")
Return Nothing
End If
Try
If type = ExecuteType.DataReader Then
Cmd = New OleDbCommand(sql, Conn)
'Dim aa As OleDbDataReader
'aa = Cmd.ExecuteReader

Return Cmd.ExecuteReader
ElseIf type = ExecuteType.DataSet Then
DA = New OleDbDataAdapter(sql, Conn)
DS = New DataSet
DA.Fill(DS)
Return DS
End If
Catch ex As Exception
Throw ex
Return Nothing
End Try
End Function

Public Property ConnString() As String
Get
Return iConnstr
End Get
Set(ByVal value As String)
iConnstr = value
End Set
End Property
Public ReadOnly Property ConnState()
Get
Return Conn.State.ToString
End Get
End Property

Public Sub Close()
Conn.Close()
End Sub
End Class
wenh7788 2007-06-14
  • 打赏
  • 举报
回复
说的清楚点好吗
dlzhangln 2007-06-14
  • 打赏
  • 举报
回复

rainbowsoftware 2007-06-14
  • 打赏
  • 举报
回复
sql
anson_515 2007-06-14
  • 打赏
  • 举报
回复
Dim a As String
a = ComboBox1.Text
Dim conn As New SqlConnection
Dim comm As New SqlCommand
conn.ConnectionString = "uid=sa;pwd=;database=自己的数据库;server=127.0.0.1"
comm.Connection = conn
If ComboBox1.Text <> "" Then
conn.Open()
comm.CommandText = "select * from 仓库表 where 仓库名称='" & a & "'"
Dim reader As SqlDataReader = comm.ExecuteReader
Dim str, i
While reader.Read()
For i = 0 To reader.FieldCount - 1
str &= reader.Item(i) & " "
Next
str &= vbCrLf
End While
MessageBox.Show(str)
conn.Close()
End If

这个可以简单的查询某个表中符合combobox1.text的记录,不知道能不能帮到你!

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧