Results 1 to 6 of 6

Thread: Field in database with space

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Question 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>

  2. #2
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    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)

  3. #3
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    The obvious thing I see is that you have Contact Name in your sql code not Company Name.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    Sorry, of course it should be "Contact Name". I still have the problem. Could it be something about using " ... [..] ..."? Perhaps it is better using ' .. [..] ..'?

  5. #5
    Member Ooogaleee's Avatar
    Join Date
    Nov 2002
    Location
    Jacksonville, FL
    Posts
    52
    Did you try: "Company_name"?

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    Yes without any luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width