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
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.
OrdersReader = Command.ExecuteReader();
// Binding the Data Reader to the GridView control
gvOrders.DataSource = OrdersReader;
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.
Read this if you want to know how to get a correct reply for your question:
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7