I do not have the book in front of me, but if you declare DBCon in your page load, that variable will only be accessible to the Page Load event. Example:
Protected Sub Page_Load(sender as object, e as eventargs)
Dim DBCon as New SqlConnection() 'This makes DBCon accessible only to the Page_Load method
'...code
End Sub
Protected Sub gvOrders_RowDataBound(sender as object, e as GridViewRowEventArgs)
Command.CommandType = CommandType.Text;
Command.Connection = DBCon; 'Error
// Opening the connection and executing the SQL query.
DBCon.Open(); 'Error
OrdersReader = Command.ExecuteReader();
// Binding the Data Reader to the GridView control
gvOrders.DataSource = OrdersReader;
gvOrders.DataBind();
End Sub
The resolution would be to add
Dim DBCon as New SqlConnection()
to your DataBound event or to declare DBCon as a class level member, which I would advise against.
hth.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========