Error Accessing Data from Access Database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shayer

    #1

    Error Accessing Data from Access Database

    Hello All,
    I write the following code to access Data from a table
    But i get the exception "Syntax Error in From Clause"

    when i write the code in SQL then it works perfectly.

    OleDbConnection Myconnection = null;

    OleDbDataReader dbReader = null;

    Myconnection = new OleDbConnection (@"Provider=Mic rosoft.Jet.OLED B.4.0; User
    Id=; Password=; Data Source=C:\STTS. mdb");

    Myconnection.Op en();

    OleDbCommand cmd = Myconnection.Cr eateCommand();

    cmd.CommandText = "SELECT * FROM user";

    dbReader = cmd.ExecuteRead er();

    string Email;

    while(dbReader. Read())

    {

    Email = (string)dbReade r.GetValue(0);

    lb.Items.Add(Em ail);

    }

    dbReader.Close( );

    Myconnection.Cl ose();



    Can anybody tell me where is the error

    Thanks


  • NULL

    #2
    Re: Error Accessing Data from Access Database

    On Tue, 2 Sep 2003 23:39:42 +1000, "Shayer" <shayer009@hotm ail.com>
    wrote:
    [color=blue]
    >Hello All,
    >I write the following code to access Data from a table
    >But i get the exception "Syntax Error in From Clause"
    >
    >when i write the code in SQL then it works perfectly.
    >Myconnection = new OleDbConnection (@"Provider=Mic rosoft.Jet.OLED B.4.0; User
    >Id=; Password=; Data Source=C:\STTS. mdb");[/color]

    Check out www.connectionstrings.com for appropriate connectionstrin gs
    for an Access DB (nice site :) very usefull):
    "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=\somepat h\mydb.mdb;User
    Id=admin;Passwo rd=;"
    [color=blue]
    >cmd.CommandTex t = "SELECT * FROM user";[/color]

    try:
    cmd.CommandText = "SELECT * FROM [user]"; //NOTE the []

    BTW, is 'user' thegood table (does it exist? I suppose so because the
    error would be another if it did not, but I'm just confirming)

    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: Error Accessing Data from Access Database

      Shayer,

      Can you provide a copy of the STTS.MDB file? The command is simple
      enough that it seems like it should work. The only thing I can think of
      would be to check the cmd variable and see that the command is not trying to
      execute a stored procedure or something like that (I don't know what the
      defaults for the instance returned from the CreateCommand method are).

      Hope this helps.


      --
      - Nicholas Paldino [.NET/C# MVP]
      - nicholas.paldin o@exisconsultin g.com

      "Shayer" <shayer009@hotm ail.com> wrote in message
      news:%2306SteVc DHA.2112@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > Hello All,
      > I write the following code to access Data from a table
      > But i get the exception "Syntax Error in From Clause"
      >
      > when i write the code in SQL then it works perfectly.
      >
      > OleDbConnection Myconnection = null;
      >
      > OleDbDataReader dbReader = null;
      >
      > Myconnection = new OleDbConnection (@"Provider=Mic rosoft.Jet.OLED B.4.0;[/color]
      User[color=blue]
      > Id=; Password=; Data Source=C:\STTS. mdb");
      >
      > Myconnection.Op en();
      >
      > OleDbCommand cmd = Myconnection.Cr eateCommand();
      >
      > cmd.CommandText = "SELECT * FROM user";
      >
      > dbReader = cmd.ExecuteRead er();
      >
      > string Email;
      >
      > while(dbReader. Read())
      >
      > {
      >
      > Email = (string)dbReade r.GetValue(0);
      >
      > lb.Items.Add(Em ail);
      >
      > }
      >
      > dbReader.Close( );
      >
      > Myconnection.Cl ose();
      >
      >
      >
      > Can anybody tell me where is the error
      >
      > Thanks
      >
      >[/color]


      Comment

      • NULL

        #4
        Re: Error Accessing Data from Access Database

        On Tue, 2 Sep 2003 09:45:47 -0400, "Nicholas Paldino [.NET/C# MVP]"
        <nicholas.paldi no@exisconsulti ng.com> wrote:

        Hey...

        What does C# MVP (Most Valued Partner??) mean... What do you have to
        do to be allowed to carry that title?

        --
        NULL

        Comment

        • Nicholas Paldino [.NET/C# MVP]

          #5
          Re: Error Accessing Data from Access Database

          NULL,

          It stands for Most Valuable Professional. It is not a certification,
          but rather an award. For more details on the MVP program, you can check out
          the following link (watch for line wrap):




          --
          - Nicholas Paldino [.NET/C# MVP]
          - nicholas.paldin o@exisconsultin g.com

          "NULL" <Thomas-dot-Delrue-at-Tiscali-dot-Be> wrote in message
          news:j989lvoves ctm2gsqkn3jvfmk 3qs3ktv1f@4ax.c om...[color=blue]
          > On Tue, 2 Sep 2003 09:45:47 -0400, "Nicholas Paldino [.NET/C# MVP]"
          > <nicholas.paldi no@exisconsulti ng.com> wrote:
          >
          > Hey...
          >
          > What does C# MVP (Most Valued Partner??) mean... What do you have to
          > do to be allowed to carry that title?
          >
          > --
          > NULL[/color]


          Comment

          • Shayer

            #6
            Re: Error Accessing Data from Access Database (Solve)

            Hello

            Everyyhing is okay here

            I have to replace the table name. I have a user table . I think User is a
            key word , i have to replace it . IF i replace it , it works perfectly

            thanks

            "NULL" <Thomas-dot-Delrue-at-Tiscali-dot-Be> wrote in message
            news:au79lv0687 0usbkp9mi56fni3 h3e8jekcd@4ax.c om...[color=blue]
            > On Tue, 2 Sep 2003 23:39:42 +1000, "Shayer" <shayer009@hotm ail.com>
            > wrote:
            >[color=green]
            > >Hello All,
            > >I write the following code to access Data from a table
            > >But i get the exception "Syntax Error in From Clause"
            > >
            > >when i write the code in SQL then it works perfectly.
            > >Myconnection = new OleDbConnection (@"Provider=Mic rosoft.Jet.OLED B.4.0;[/color][/color]
            User[color=blue][color=green]
            > >Id=; Password=; Data Source=C:\STTS. mdb");[/color]
            >
            > Check out www.connectionstrings.com for appropriate connectionstrin gs
            > for an Access DB (nice site :) very usefull):
            > "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=\somepat h\mydb.mdb;User
            > Id=admin;Passwo rd=;"
            >[color=green]
            > >cmd.CommandTex t = "SELECT * FROM user";[/color]
            >
            > try:
            > cmd.CommandText = "SELECT * FROM [user]"; //NOTE the []
            >
            > BTW, is 'user' thegood table (does it exist? I suppose so because the
            > error would be another if it did not, but I'm just confirming)[/color]


            Comment

            Working...