Vill skriva ut alla användarnam från en tabell i en access databas i en dropdownlist. Hur gör man det enklast? Fick flera felmeddelande men löste det såhär: Fick flera felmeddelande men löste det såhär:Fylla DropDownList
Har gjort följande:
Sub getUserInfo()
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim myDataReader As OleDbDataReader
myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("databases/ForumDB.mdb;Persist Security Info=False;"))
myConnection.Open()
myCommand = New OleDbCommand("SELECT [tblMember].[Username] FROM [tblMember]", myConnection)
myDataReader = myCommand.ExecuteReader
While myDataReader.Read()
dropdownlistid.Items.Add(New ListItem(myDataReader("Username"), myDataReader("Username")))
End While
End Sub
<asp:DropDownList Runat="server" ID="dropdownlistid"><asp:ListItem text="Välj en användare" /></asp:DropDownList>
Men får inte ut något mer än "Välj en användare" i dropdownlistan..
Vad är fel och kan hur kan man göra på något annat sätt? Är ny på asp.netSv:Fylla DropDownList
Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs) Handles MyBase.Load
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim myDataReader As OleDbDataReader
myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("databases/ForumDB.mdb;Persist Security Info=False;"))
myConnection.Open()
myCommand = New OleDbCommand("SELECT * FROM [tblMember]", myConnection)
myDataReader = myCommand.ExecuteReader
While myDataReader.Read()
ddlUsername.Items.Add(New ListItem(myDataReader("Username"), myDataReader("Username")))
End While
End Sub
<asp:DropDownList Runat="server" ID="ddlUsername" AutoPostBack="false"><asp:ListItem text="Välj en användare" /></asp:DropDownList>Sv:Fylla DropDownList
Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs) Handles MyBase.Load
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim myDataReader As OleDbDataReader
myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("databases/ForumDB.mdb;Persist Security Info=False;"))
myConnection.Open()
myCommand = New OleDbCommand("SELECT * FROM [tblMember]", myConnection)
myDataReader = myCommand.ExecuteReader
While myDataReader.Read()
ddlUsername.Items.Add(New ListItem(myDataReader("Username"), myDataReader("Username")))
End While
End Sub
<asp:DropDownList Runat="server" ID="ddlUsername" AutoPostBack="false"><asp:ListItem text="Välj en användare" /></asp:DropDownList>