把sql字符串中选择的内容显示在ListView
来源:互联网 发布:java系统业务日志设计 编辑:程序博客网 时间:2024/04/30 14:07
'【功能】:【显示ListView中的内容】
'【输入】:【连接字符串,要显示字符串,是否显示check框,是哪种访问数据库的方式】
'【输出】:【数据库的查询内容在ListView中显示】
'【参数】:【showStr,传值调用】
Private Sub showListView(ByVal strConn As String, ByVal showStr As String, ByVal check As Boolean, ByVal dataAccess As String)
If dataAccess = "sql" Then
'[用于sql查询]
Dim sqlConn As SqlClient.SqlConnection
Dim sqlReader As SqlClient.SqlDataReader
Dim sqlCmd As SqlClient.SqlCommand
Try
sqlConn = New SqlClient.SqlConnection(strConn)
sqlConn.Open()
sqlCmd = New SqlClient.SqlCommand(showStr, sqlConn)
sqlReader = sqlCmd.ExecuteReader
'【加入listview的头标题】
Dim iHead As Integer
ListView1.Columns.Clear()
For iHead = 0 To sqlReader.FieldCount - 1
ListView1.Columns.Add(sqlReader.GetName(iHead), 100, HorizontalAlignment.Center)
Next
'[加入每一列数据]
ListView1.Items.Clear()
Dim iRow As Long = 0
Dim iRowHead As Int16
While sqlReader.Read
ListView1.Items.Add(sqlReader(0))
For iRowHead = 1 To sqlReader.FieldCount - 1
If (sqlReader(irowhead) Is System.DBNull.value = False) Then
ListView1.Items(iRow).SubItems.Add(CStr(sqlReader(iRowHead)))
Else
ListView1.Items(irow).SubItems.Add(" ")
End If
Next
iRow = iRow + 1
End While
Catch
MessageBox.Show(Err.Description, clewInfo, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
sqlConn.Close()
Exit Sub
End Try
sqlReader.Close()
sqlCmd.Dispose()
sqlConn.Close()
Else
'[用于ole查询]
Dim oleConn As OleDb.OleDbConnection
Dim oleReader As OleDb.OleDbDataReader
Dim oleCmd As OleDb.OleDbCommand
Try
oleConn = New OleDb.OleDbConnection(strConn)
oleConn.Open()
oleCmd = New OleDb.OleDbCommand(showStr, oleConn)
oleReader = oleCmd.ExecuteReader
'【加入listview的头标题】
Dim iHead As Integer
ListView1.Columns.Clear()
For iHead = 0 To oleReader.FieldCount - 1
ListView1.Columns.Add(oleReader.GetName(iHead), 100, HorizontalAlignment.Center)
Next
'[加入每一列数据]
ListView1.Items.Clear()
Dim iRow As Long = 0
Dim iRowHead As Int16
While oleReader.Read()
ListView1.Items.Add(oleReader(0))
For iRowHead = 1 To oleReader.FieldCount - 1
If oleReader(irowhead) Is System.DBNull.value = False Then
ListView1.Items(iRow).SubItems.Add(CStr(oleReader(iRowHead)))
Else
ListView1.Items(irow).SubItems.Add(" ")
End If
Next
iRow = iRow + 1
End While
Catch
MessageBox.Show(Err.Description, clewInfo, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
oleConn.Close()
Exit Sub
End Try
oleReader.Close()
oleCmd.Dispose()
oleConn.Close()
End If
'【加入底色】
Dim i As Integer
For i = 0 To ListView1.Items.Count - 1
If i Mod 2 = 0 Then
ListView1.Items(i).BackColor = Color.LightBlue
Else
ListView1.Items(i).BackColor = Color.OldLace
End If
Next i
'[是否显示check按钮]
If check = True Then
ListView1.CheckBoxes = True
Else
ListView1.CheckBoxes = False
End If
End Sub
- 把sql字符串中选择的内容显示在ListView
- android中ListView中嵌套GridView并且把GridView当中的内容全部显示出来的方法
- 常见适配器的用法(在listview中 ,把三个edittext内容放在简单适配器中)
- 页面跳转+把数据库中查出的内容显示在该页面上
- 在webform1中打开webform2选择数据,最后还要把webform2中选择的数据传回webform1显示出来
- 在TXT文件中查找指定字符串并显示指定字符串所在行的内容
- Linux中把文件夹中替换文件内容的字符串
- 将XML解析出的内容显示在ListView上
- 如何把cmd中显示的的内容复制出来?
- Android 关于在ScrollView中加上一个ListView,ListView内容显示不完全(总是显示第一项)的问题的两种简单的解决方案
- 在SQL中,把字符串装换为日期
- SQL语句中把多条记录同一字段的值连接成一个字符串显示结果集(sql stuff)
- android中如何让listview的内容全部显示出来
- 修改listview的显示内容
- Assets的使用,外部sql文件,并显示在listview中
- 在文本框中显示文本的内容
- 在表格中显示数据表的内容
- 在ListView中显示图片及ListView的动态刷新
- 劝解失恋的JJ
- 趣味密码学之四:恺撒大帝的秘密——替代之恺撒码
- 完成linux命令行长宽认证程序
- 《凹凸》
- 2004,看不懂看不懂
- 把sql字符串中选择的内容显示在ListView
- 亚洲杯决赛
- Java中float的取值范围
- Bugzilla简明使用手则
- C delphi python
- 听说delphi9要出来了
- base64编码
- ANSI vs UNICODE
- 超越车田正美