Dear All,
When I run an example program on the
http://www.dotnetjunkies.com/quickst...d1.aspx&font=3
I received an error message:
"The ConnectionStrin g property has not been initialized.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.InvalidO perationExcepti on: The ConnectionStrin g
property has not been initialized.
Source Error:
Line 11: Line 12: DataSet ds = new DataSet();Line 13:
myCommand.Fill( ds, "Authors"); Line 14: Line 15:
MyDataGrid.Data Source=ds.Table s["Authors"].DefaultView;"C an you tell me
what's wrong? Thanks!
The example code is below:
=============== =======
<%@ Import Namespace="Syst em.Data" %>
<%@ Import Namespace="Syst em.Data.SqlClie nt" %>
<html>
<script language="VB" runat="server">
Sub Page_Load(Sende r As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
MyConnection = New
SqlConnection(S ystem.Configura tion.Configurat ionSettings.App Settings("PubsS t
ring"))
MyCommand = New SqlDataAdapter( "select * from Authors",
MyConnection)
DS = new DataSet()
MyCommand.Fill( ds, "Authors")
MyDataGrid.Data Source=ds.Table s("Authors").De faultView
MyDataGrid.Data Bind()
End Sub
</script>
<body>
<h3><font face="Verdana"> Simple Select to a DataGrid Control</font></h3>
<ASP:DataGrid id="MyDataGrid " runat="server"
Width="700"
BackColor="#ccc cff"
BorderColor="bl ack"
ShowFooter="fal se"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaa add"
EnableViewState ="false"
/>
</body>
</html>