I try to retrieve data from the Northwind database from the field named "Company Name" (including a space). I have tried the code below using brackets, but it doesn't work.
Code:<%@ Page Language="vb" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.OleDb" %> <script runat="server"> Sub Page_Load() dim strConnection as string = "Provider=Microsoft.Jet.OLEDB.4.0;" strConnection += "Data source=C:\BegASPNET\ch12\northwind.mdb;" dim strSQL as string = "Select Address, City, [Contact Name], Phone from suppliers;" dim objConnection as new OLEDBConnection(strConnection) dim objCommand as new OLEDBCommand(strSQL,objConnection) objConnection.Open() dgEmps.DataSource = objCommand.ExecuteReader(CommandBehavior.CloseConnection) dgEmps.DataBind() end sub </script> <html> <head> </head> <body> <h2>Using ExecuteReader to create a table </h2> <asp:datagrid id="dgEmps" HeaderStyle-ForeColor="blue" HeaderStyle-BackColor="#dcdcdc" Font-Size="8pt" Font-Name="arial" CellPadding="3" runat="server"></asp:datagrid> </body> </html>




Reply With Quote