T
Troy
Hello,
I'm learning asp.net so please excuse the question: I;d list to populate the
listbox control with data from sql and I have no idea on how to do it.
Below is my code that displays it in a datagrid.
TIA
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.sqlclient" %>
<%@ Page Language="vb" Debug="true" %>
<script language="vb" runat="server">
'Place the following in a server side script in your aspx or in the
codebehind:
Sub Page_Load(Sender As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = new
sqlConnection("server=ServerA;uid=app;pwd=password;database=northwind")
MyCommand = New SqlDataAdapter("select CompanyName from Customers",
MyConnection)
DS = new DataSet()
MyCommand.Fill(ds, "Customers")
MyDataGrid.DataSource=ds.Tables("Customers").DefaultView
MyDataGrid.DataBind()
End Sub
</script>
<html>
<body>
<form runat="server">
<aspataGrid id="MyDataGrid" runat="Server" font-size="10" />
</form>
</body>
I'm learning asp.net so please excuse the question: I;d list to populate the
listbox control with data from sql and I have no idea on how to do it.
Below is my code that displays it in a datagrid.
TIA
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.sqlclient" %>
<%@ Page Language="vb" Debug="true" %>
<script language="vb" runat="server">
'Place the following in a server side script in your aspx or in the
codebehind:
Sub Page_Load(Sender As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = new
sqlConnection("server=ServerA;uid=app;pwd=password;database=northwind")
MyCommand = New SqlDataAdapter("select CompanyName from Customers",
MyConnection)
DS = new DataSet()
MyCommand.Fill(ds, "Customers")
MyDataGrid.DataSource=ds.Tables("Customers").DefaultView
MyDataGrid.DataBind()
End Sub
</script>
<html>
<body>
<form runat="server">
<aspataGrid id="MyDataGrid" runat="Server" font-size="10" />
</form>
</body>