|
-
Jan 8th, 2003, 07:26 AM
#1
Thread Starter
Frenzied Member
Field in database with space
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>
-
Jan 8th, 2003, 12:01 PM
#2
What is the error you receive?
Brackets are the correct way to reference fields with special characters.
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Jan 8th, 2003, 02:06 PM
#3
Hyperactive Member
The obvious thing I see is that you have Contact Name in your sql code not Company Name.
-
Jan 9th, 2003, 01:59 AM
#4
Thread Starter
Frenzied Member
Sorry, of course it should be "Contact Name". I still have the problem. Could it be something about using " ... [..] ..."? Perhaps it is better using ' .. [..] ..'?
-
Jan 9th, 2003, 04:17 AM
#5
Member
Did you try: "Company_name"?
-
Jan 9th, 2003, 04:18 AM
#6
Thread Starter
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|