I'm very new to asp.net and I have a general question about datalists. I was able to get this to work, but I don't understand how really. I think I need someone to give me the "theory" on this.
So first I connect to the database:
Dim MyConnection As SqlConnection
MyConnection = New SqlConnection("myconnectionstring=workingfine")
Dim DS As New DataSet
Dim MyCommand As New SqlDataAdapter("select * from thetable", MyConnection)
MyCommand.Fill(DS, "field1")
MyDataList.DataSource = DS.Tables("field1").DefaultView
MyDataList.DataBind()
Then I output it like this:
<form runat="server" id="form1">
<asp:datalist ID="MyDataList" runat="server">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"field1") %>
<%#DataBinder.Eval(Container.DataItem,"field2") %>
</ItemTemplate>
</asp:datalist>
</form>
Here are my questions:
- Why is the datalist pulling field2 successfully?
- Are the MyCommand.Fill(DS, "field1") and DS.Tables("field1").DefaultView meaningless?
- I guess my bottom-line question is, why do I have to specify fields in the vb if I can output any field?
I think I need some general guidance...