0

I want to load database tables in dropdown list and display selected table in grid view. I am trying to convert the following code into asp. Net.

I am getting error as, 
Variable conflicts with property adapter 
Private adapter As New OleDbDataAdapter(String.Empty, Me.con)

                                                                                                                   DisplayMember' is not a member of 'System.Web.UI.WebControls.DropDownList'        ValueMember' is not a member of 'System.Web.UI.WebControls.DropDownList'.          Me.DropDownList1.DisplayMember = "TABLE_NAME"
                                                                                                                   can someone help me in this regard?




Public Class WebForm1
 Inherits System.Web.UI.Page


    Private con As New OleDbConnection("  Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\dtb.accdb;Jet OLEDB:Database Password=****  ")
    Private adapter As New OleDbDataAdapter(String.Empty, Me.con)
    Private data As DataTable
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        con.Open()

        Me.DropDownList1.DisplayMember = "TABLE_NAME"
        Me.DropDownList1.ValueMember = "TABLE_NAME"
        Me.DropDownList1.DataSource = Me.con.GetSchema("TABLES", New String() {Nothing, Nothing, Nothing, "TABLE"})
        con.Close()
    End Sub



    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList1.SelectedIndexChanged
        If Me.DropDownList1.SelectedItem IsNot Nothing Then
            Me.data = New DataTable
            Me.adapter.SelectCommand.CommandText = String.Format("SELECT * FROM [{0}]", Me.DropDownList1.SelectedValue)
            Me.adapter.Fill(data)
            Me.GridView1.DataSource = Nothing
            Me.GridView1.Columns.Clear()
            Me.GridView1.DataSource = Me.data
        End If
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        ' Dim thisConnection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Dtb.accdb")

        If Me.data IsNot Nothing Then
            Dim builder As New OleDbCommandBuilder(Me.adapter)
            Me.adapter.Update(Me.data)
        End If
    End Sub
2
Contributors
2
Replies
21
Views
3 Years
Discussion Span
Last Post by Josefo1
0

DisplayMember and valueMember aren't properties of the DropDownList.
You simply can't use them as they aren't relevant to that control.

0

thank you for your reply
I have one more question, how do i fix the error
Variable conflicts with property adapter
Private adapter As New OleDbDataAdapter(String.Empty, Me.con)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.