本文介绍了将dbf文件显示到vb.net的列表视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 嗨......我这里有一些代码显示所有数据..这里的问题是如何获得数据的第二列?我只能得到第一列。 这是我的代码..你可以帮帮我吗? 私人 Sub dbffrm_Load(发件人作为 对象,e As EventArgs)句柄 MyBase .Load Companydbf = C:\ PAY \ Dim ConnectionString As String = 字符串 .Empty,sCommand 作为 字符串 = 字符串 .Empty Dim xlApp As Excel.Application = 没什么,xlWorkBook As Excel.Workbook = Nothing ,xlWorkSheet As Excel.Worksheet = Nothing ,xlRange As Excel.Range = Nothing Dim dBaseConnection As OleDb.OleDbConnection = Nothing ,dBaseCommand As OleDb.OleDbCommand = Nothing Dim retVal 作为 整数 = 0 Dim reader As OleDbDataReader 尝试 ' 如果使用visual fox pro连接到单个DBF文件 ConnectionString = Provider = vfpoledb; Data Source =& IO.Path.GetDirectoryName(Companydbf)& ;整理顺序=机器; dBaseConnection = 新 OleDb.OleDbConnection(ConnectionString) dBaseConnection.Open() sCommand = 从company.dbf中选择* dBaseCommand = 新 OleDbCommand(sCommand,dBaseConnection) ' myDA =新OleDbDataAdapter(comm) ' dBaseCommand =新的OleDb.OleDbCommand(sCommand,dBaseConnection) retVal = dBaseCommand.ExecuteNonQuery() reader = dBaseCommand.ExecuteReader( ) ' Dim intCount As Decimal = 0 ListView1.View = View.Details ListView1.GridLines = True ListView1.FullRowSelect = True ListView1.HideSelection = False ListView1.MultiSelect = False ListView1.Columns.Add( 公司名称) ListView1.Columns.Add( 目录名称) while reader.Read() Dim lvi As New ListViewItem lvi.Text = reader( CONA我)。ToString ' 第二栏 lvi。 SubItems.Add(reader( DIRNAME)。ToString) ListView1.Items.Add(lvi) ' intCount = intCount + 1 结束 while dBaseConnection.Close() Catch ex As System.InvalidCastException MsgBox(ex.Message,MsgBoxStyle。感叹号, 错误...) Catch ex As OleDb.OleDbException MsgBox(ex.Message,MsgBoxStyle.Exclamation, 错误...) Catch ex As System.NullReferenceException MsgBox(ex.Message,MsgBoxStyle.Exclamation , 错误...) Catch ex As Exception MsgBox(ex.Message,MsgBoxStyle.Exclamation, 错误...) 结束 尝试 结束 Sub 私有 Sub ListView1_SelectedIndexChanged( ByVal sender As _ System。 Object , ByVal e As System.EventArgs)_ 句柄 ListView1.SelectedIndexChanged 如果 ListView1.SelectedIndices.Count = 0 那么 返回 Dim lvi 作为 ListViewItem = _ ListView1.SelectedItems( 0 ) ' MessageBox.Show(已选择lvi.Text +。) nxtbtn3.Enabled = True Companydbf = lvi.Text MessageBox.Show(Companydbf) End Sub 解决方案 私有 Sub ListView1_SelectedIndexChanged( ByVal sender As _ System。 Object , ByVal e As System.EventArgs)_ 句柄 ListView1.SelectedIndexChanged 如果 ListView1.SelectedIndices.Count = 0 然后 返回 Dim lvi 作为 ListViewItem = _ ListView1.SelectedItems( 0 ) nxtbtn3.Enabled = True Companydbf = lvi.SubItems( 1 )。文字 结束 Sub hi...i have some code here display all data..the problem here is how can i get the second column of the data? i only can get the first column.here is my code..can u help me? Private Sub dbffrm_Load(sender As Object, e As EventArgs) Handles MyBase.Load Companydbf = "C:\PAY\" Dim ConnectionString As String = String.Empty, sCommand As String = String.Empty Dim xlApp As Excel.Application = Nothing, xlWorkBook As Excel.Workbook = Nothing, xlWorkSheet As Excel.Worksheet = Nothing, xlRange As Excel.Range = Nothing Dim dBaseConnection As OleDb.OleDbConnection = Nothing, dBaseCommand As OleDb.OleDbCommand = Nothing Dim retVal As Integer = 0 Dim reader As OleDbDataReader Try 'if use visual fox pro Connect to a single DBF-file ConnectionString = "Provider=vfpoledb;Data Source=" & IO.Path.GetDirectoryName(Companydbf) & ";Collating Sequence=machine;" dBaseConnection = New OleDb.OleDbConnection(ConnectionString) dBaseConnection.Open() sCommand = "Select * from company.dbf " dBaseCommand = New OleDbCommand(sCommand, dBaseConnection) 'myDA = New OleDbDataAdapter(comm) 'dBaseCommand = New OleDb.OleDbCommand(sCommand, dBaseConnection) retVal = dBaseCommand.ExecuteNonQuery() reader = dBaseCommand.ExecuteReader() 'Dim intCount As Decimal = 0 ListView1.View = View.Details ListView1.GridLines = True ListView1.FullRowSelect = True ListView1.HideSelection = False ListView1.MultiSelect = False ListView1.Columns.Add("Company Name") ListView1.Columns.Add("Directory Name") While reader.Read() Dim lvi As New ListViewItem lvi.Text = reader("CONAME").ToString ' second column lvi.SubItems.Add(reader("DIRNAME").ToString) ListView1.Items.Add(lvi) 'intCount = intCount + 1 End While dBaseConnection.Close() Catch ex As System.InvalidCastException MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...") Catch ex As OleDb.OleDbException MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...") Catch ex As System.NullReferenceException MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...") Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error...") End Try End SubPrivate Sub ListView1_SelectedIndexChanged(ByVal sender As _ System.Object, ByVal e As System.EventArgs) _ Handles ListView1.SelectedIndexChanged If ListView1.SelectedIndices.Count = 0 Then Return Dim lvi As ListViewItem = _ ListView1.SelectedItems(0) 'MessageBox.Show(lvi.Text + " has been selected.") nxtbtn3.Enabled = True Companydbf = lvi.Text MessageBox.Show(Companydbf) End Sub 解决方案 Private Sub ListView1_SelectedIndexChanged(ByVal sender As _ System.Object, ByVal e As System.EventArgs) _ Handles ListView1.SelectedIndexChanged If ListView1.SelectedIndices.Count = 0 Then Return Dim lvi As ListViewItem = _ ListView1.SelectedItems(0) nxtbtn3.Enabled = True Companydbf = lvi.SubItems(1).Text End Sub 这篇关于将dbf文件显示到vb.net的列表视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-05 06:17