VB图书管理系统源代码 第4页
Dim SqlString As String
Dim OrderString As String
Dim QueryString As String
'这三个字符串变量用来存储查询语句
'SqlString变量用来存储查询语句中除了ORDER BY子句之外的部分
'OrderString变量用来存储ORDER BY子句
'QueryString变量存储查询语句
Private Sub 综合查询_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'初始化列表“cmbBox查询表”
Me.cmbBox查询表.Items.Add("读者信息")
Me.cmbBox查询表.Items.Add("管理者信息")
Me.cmbBox查询表.Items.Add("借阅信息")
Me.cmbBox查询表.Items.Add("书籍信息")
Me.cmbBox查询表.Items.Add("出版社信息")
Me.cmbBox查询表.SelectedIndex = 0 '将列表的第一项设为选中项
End Sub
Private Sub cmbBox查询表_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbBox查询表.SelectedIndexChanged
'在“cmbBox查询表”中选择一项作为查询表
'则在“cmbBox查询依据”“cmbBox排序依据”将自动填充
'查询表中的所有字段
'保持数据表与字段二者的一致性
Dim str_Table As String
str_Table = Me.cmbBox查询表.SelectedItem
If str_Table = "" Then Return
Me.cmbBox查询依据.Items.Clear()
Me.cmbBox排序依据.Items.Clear()
Dim mySelectQuery As String = "SELECT * FROM " + str_Table
Dim myCommand As New OleDb.OleDbCommand(mySelectQuery, Me.OleDbConnection1)
If Me.OleDbConnection1.State = ConnectionState.Closed Then
Me.OleDbConnection1.Open()
End If
Dim myReader As OleDb.OleDbDataReader
myReader = myCommand.ExecuteReader
Dim i As Integer
For i = 0 To myReader.FieldCount - 1
DataType(i) = myReader.GetFieldType(i).Name
Me.cmbBox排序依据.Items.Add(myReader.GetName(i).ToString)
Me.cmbBox查询依据.Items.Add(myReader.GetName(i).ToString)
Next
myReader.Close()
Me.cmbBox查询依据.SelectedIndex = 0
Me.cmbBox排序依据.SelectedIndex = 0
End Sub
Private Sub btn执行查询_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn执行查询.Click
If DataType(Me.cmbBox查询依据.SelectedIndex) = "Int32" Then
SqlString = "SELECT * FROM " + Me.cmbBox查询表.Text + " WHERE"
SqlString = SqlString + Me.cmbBox查询依据.Text + " " + _
Me.cmbBox运算符.Text + " " + "(" + Me.edit指定值.Text + ")"
ElseIf DataType(Me.cmbBox查询依据.SelectedIndex) = "String" Then
SqlString = "SELECT * FROM " + Me.cmbBox查询表.Text + " WHERE"
SqlString = SqlString + Me.cmbBox查询依据.Text + " " + _
Me.cmbBox运算符.Text + " " + "'" + Me.edit指定值.Text + "'"
ElseIf DataType(Me.cmbBox查询依据.SelectedIndex) = "Date" Then
SqlString = "SELECT * FROM " + Me.cmbBox查询表.Text + " WHERE"
SqlString = SqlString + Me.cmbBox查询依据.Text + " " + _
Me.cmbBox运算符.Text + "Cdate(" + Me.edit指定值.Text + ")"
End If
OrderString = Me.cmbBox排序依据.Text
QueryData(SqlString, OrderString)
If Me.cmbBox查询表.Text = "读者信息" Then
Me.OleDbInsertCommand2.CommandText = QueryString
End If
If Me.cmbBox查询表.Text = "管理者信息" Then
Me.OleDbInsertCommand3.CommandText = QueryString
End If
If Me.cmbBox查询表.Text = "借阅信息" Then
Me.OleDbInsertCommand4.CommandText = QueryString
End If
If Me.cmbBox查询表.Text = "书籍信息" Then
Me.OleDbInsertCommand5.CommandText = QueryString
End If
If Me.cmbBox查询表.Text = "出版社信息" Then
Me.OleDbInsertCommand1.CommandText = QueryString
End If
Try
Me.LoadDataSet() '尝试加载数据集
Me.DataGrid1.DataMember = Me.cmbBox查询表.Text
Catch eLoad As System.Exception
System.Windows.Forms.MessageBox.Show(eLoad.Message)
End Try
End Sub
上一页 [1] [2] [3] [4] [5] [6] [7] [8] 下一页
VB图书管理系统源代码 第4页下载如图片无法显示或论文不完整,请联系qq752018766