none
ComboBox2无法绑定到数据源,显示System.Data.DataRowView RRS feed

  • 问题

  • Public Class 添加信息
        Function seekinfo(ByVal SQLstr As String, ByVal TableName As String, ByVal filedname As String)
            '在数据库中搜索数据name 
            Dim DatabasePath As String = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\结算计价信息系统.mdb"
            Using ConnForm As New OleDb.OleDbConnection(DatabasePath)
                Dim DataSetInfo As New DataSet
                ConnForm.Open()
                Dim SqlStrForm = "SELECT 合作单位名称 FROM 施工合作单位信息表"
                Dim AdapterForm As New OleDb.OleDbDataAdapter(SqlStrForm, ConnForm)
                AdapterForm.Fill(DataSetInfo, TableName)
                Return DataSetInfo.Tables(TableName)
            End Using
        End Function
        Private Sub 添加公司信息_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'MessageBox.Show(Form1.TreeNodeInfo.Label公司名称.ToString)
            If Form1.TreeNodeInfo.Label公司名称.ToString <> "" And Form1.TreeNodeInfo.Label合同名称 Is Nothing And Form1.TreeNodeInfo.Label结算单标签 Is Nothing Then
                Label1.Text = Form1.TreeNodeInfo.Label公司名称
                Dim SqlStrForm As String = "SELECT 合作单位名称 FROM 施工合作单位信息表"
                Dim TableName As String = "施工合作单位信息表"
                Dim filedname As String = "合作单位名称"
                combobox1.DataSource = seekinfo(SqlStrForm, TableName, filedname)
                combobox1.DisplayMember = "合作单位名称"
                combobox1.SelectedIndex = combobox1.FindStringExact(Form1.TreeNodeInfo.公司名称.ToString)
                Label2.Visible = False
                ComboBox2.Visible = False
                Label3.Visible = False
                ComboBox3.Visible = False
            ElseIf Form1.TreeNodeInfo.Label公司名称.ToString <> "" And Form1.TreeNodeInfo.Label合同名称.ToString <> "" And Form1.TreeNodeInfo.Label结算单标签 Is Nothing Then
                Label1.Text = Form1.TreeNodeInfo.Label公司名称
                Label2.Text = Form1.TreeNodeInfo.Label合同名称
                Dim SqlStrCompany As String = "SELECT 合作单位名称 FROM 施工合作单位信息表"
                Dim TableNameCompany As String = "施工合作单位信息表"
                Dim filednameCompany As String = "合作单位名称"
                combobox1.DataSource = seekinfo(SqlStrCompany, TableNameCompany, filednameCompany)
                combobox1.DisplayMember = "合作单位名称"
                combobox1.SelectedIndex = combobox1.FindStringExact(Form1.TreeNodeInfo.公司名称.ToString)
                Dim SqlStrContract As String = "SELECT 合同名称 FROM 施工合同信息表"
                Dim TableNameContract As String = "施工合同信息表"
                Dim filednameContract As String = "合同名称"
                ComboBox2.DataSource = seekinfo(SqlStrContract, TableNameContract, filednameContract)
                ComboBox2.DisplayMember = "合同名称"
    'ComboBox2无法绑定到数据源,显示System.Data.DataRowView
                ComboBox2.SelectedIndex = ComboBox2.FindStringExact(Form1.TreeNodeInfo.合同名称.ToString)
                Label2.Visible = True
                ComboBox2.Visible = True
                Label3.Visible = False
                ComboBox3.Visible = False
            ElseIf


    http://hi.baidu.com/useek/blog

    2012年3月25日 9:56

答案

  • 函数写错了,粗心大意,对不起,谢谢关注,浪费大家时间了,想下面这样写执行结果正常了。
    Function seekinfo(ByVal SQLstr As String, ByVal TableName As String, ByVal filedname As String)
            '在数据库中搜索数据name 
            Dim DatabasePath As String = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\结算计价信息系统.mdb"
            Using ConnForm As New OleDb.OleDbConnection(DatabasePath)
                Dim DataSetInfo As New DataSet
                ConnForm.Open()
    
                Dim AdapterForm As New OleDb.OleDbDataAdapter(SQLstr, ConnForm)
                AdapterForm.Fill(DataSetInfo, TableName)
                Return DataSetInfo.Tables(TableName)
            End Using
        End Function


    http://hi.baidu.com/useek/blog


    • 已编辑 firedream 2012年3月25日 10:14
    • 已标记为答案 firedream 2012年3月25日 10:14
    2012年3月25日 10:12