Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. error in query with 2 tables in c# visual studio 2010

error in query with 2 tables in c# visual studio 2010

Scheduled Pinned Locked Moved C#
csharpdatabasevisual-studiohelpquestion
13 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User3490
    wrote on last edited by
    #1

    why is my query wrong at FROM ? i want to connect two tables so i can get some specific data but c# appear error. try { //Set the command string string Cmd = "SELECT * FROM Robberies_Table JOIN Branches_Table ON Robberies_Table.BranchCode =Branches_Table.BranchCode ;"; //create new new connection to the database OleDbConnection conn = new OleDbConnection(ConnectionString); //create new data adapter OleDbDataAdapter Adapter = new OleDbDataAdapter(Cmd, conn); //create new command builder OleDbCommandBuilder CmdBuilder = new OleDbCommandBuilder(Adapter); dTable = new DataTable(); Adapter.Fill(dTable); conn.Close(); } catch (Exception e) { MessageBox.Show(e.ToString()); } //return the search results on a datatable return dTable; }

    P R 2 Replies Last reply
    0
    • U User3490

      why is my query wrong at FROM ? i want to connect two tables so i can get some specific data but c# appear error. try { //Set the command string string Cmd = "SELECT * FROM Robberies_Table JOIN Branches_Table ON Robberies_Table.BranchCode =Branches_Table.BranchCode ;"; //create new new connection to the database OleDbConnection conn = new OleDbConnection(ConnectionString); //create new data adapter OleDbDataAdapter Adapter = new OleDbDataAdapter(Cmd, conn); //create new command builder OleDbCommandBuilder CmdBuilder = new OleDbCommandBuilder(Adapter); dTable = new DataTable(); Adapter.Fill(dTable); conn.Close(); } catch (Exception e) { MessageBox.Show(e.ToString()); } //return the search results on a datatable return dTable; }

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Your SQL query has a semi-colon in there. Remove it.

      I was brought up to respect my elders. I don't respect many people nowadays.
      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

      U 1 Reply Last reply
      0
      • P Pete OHanlon

        Your SQL query has a semi-colon in there. Remove it.

        I was brought up to respect my elders. I don't respect many people nowadays.
        CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

        U Offline
        U Offline
        User3490
        wrote on last edited by
        #3

        i remove inner semi-colon but the query has error again at from field . string Cmd = "SELECT * FROM Robberies_Table JOIN Branches_Table ON Robberies_Table.BranchCode =Branches_Table.BranchCode ";

        P 1 Reply Last reply
        0
        • U User3490

          i remove inner semi-colon but the query has error again at from field . string Cmd = "SELECT * FROM Robberies_Table JOIN Branches_Table ON Robberies_Table.BranchCode =Branches_Table.BranchCode ";

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          A couple of things:

          1. What error does it come up with? Give us a fighting chance here.
          2. What happens if you run this query directly against your database?

          I was brought up to respect my elders. I don't respect many people nowadays.
          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

          U 1 Reply Last reply
          0
          • P Pete OHanlon

            A couple of things:

            1. What error does it come up with? Give us a fighting chance here.
            2. What happens if you run this query directly against your database?

            I was brought up to respect my elders. I don't respect many people nowadays.
            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

            U Offline
            U Offline
            User3490
            wrote on last edited by
            #5

            THE QUERY RUN SUCCESSFULLY AND IS IN THIS FORMAT:

            SELECT Robberies_Table.BankName, Robberies_Table.Region, Robberies_Table.BranchCode, Robberies_Table.[Date], Robberies_Table.Ammount,
            Robberies_Table.Description, Robberies_Table.Robbery_ID, Robberies_Table.[Year], Branches_Table.BranchName
            FROM (Robberies_Table INNER JOIN
            Branches_Table ON Robberies_Table.BranchCode = Branches_Table.BranchCode)

            IN C# THE QUERY I WRITE IS LIKE THIS : string Cmd = "SELECT * FROM (Robberies_Table INNER JOIN Branches_Table ON Robberies_Table.BranchCode = Branches_Table.BranchCode);"; AND WHEN I RUN THE PROGRAM NOW ONLY THE RECORD IS UNDER THE BRANCHNAME IT APPEAR IN SCREEN THE DATA OF ROBBERIES TABLE DON'T SHOW ME

            P 1 Reply Last reply
            0
            • U User3490

              THE QUERY RUN SUCCESSFULLY AND IS IN THIS FORMAT:

              SELECT Robberies_Table.BankName, Robberies_Table.Region, Robberies_Table.BranchCode, Robberies_Table.[Date], Robberies_Table.Ammount,
              Robberies_Table.Description, Robberies_Table.Robbery_ID, Robberies_Table.[Year], Branches_Table.BranchName
              FROM (Robberies_Table INNER JOIN
              Branches_Table ON Robberies_Table.BranchCode = Branches_Table.BranchCode)

              IN C# THE QUERY I WRITE IS LIKE THIS : string Cmd = "SELECT * FROM (Robberies_Table INNER JOIN Branches_Table ON Robberies_Table.BranchCode = Branches_Table.BranchCode);"; AND WHEN I RUN THE PROGRAM NOW ONLY THE RECORD IS UNDER THE BRANCHNAME IT APPEAR IN SCREEN THE DATA OF ROBBERIES TABLE DON'T SHOW ME

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              So use that query in your code.

              I was brought up to respect my elders. I don't respect many people nowadays.
              CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

              U 1 Reply Last reply
              0
              • P Pete OHanlon

                So use that query in your code.

                I was brought up to respect my elders. I don't respect many people nowadays.
                CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                U Offline
                U Offline
                User3490
                wrote on last edited by
                #7

                IN C# THE QUERY I WRITE IS LIKE THIS : string Cmd = "SELECT * FROM (Robberies_Table INNER JOIN Branches_Table ON Robberies_Table.BranchCode = Branches_Table.BranchCode);"; AND WHEN I RUN THE PROGRAM NOW ONLY THE RECORD IS UNDER THE BRANCHNAME IT APPEAR IN SCREEN THE DATA OF ROBBERIES TABLE DON'T SHOW ME IF I WRITE THE SAME THAT IS IN MY DATABASE QUERY C# SHOW ME MY CRYSTAL REPORT EMPTY SO I WRITE AS ABOVE AND HAS THE ABOVE ERROR DIDN'T SHOW ANYTHING: ------------------------ string Cmd = "SELECT Robberies_Table.BankName, Robberies_Table.Region, Robberies_Table.BranchCode, Robberies_Table.[Date], Robberies_Table.Ammount,Robberies_Table.Description, Robberies_Table.Robbery_ID, Robberies_Table.[Year], Branches_Table.BranchName FROM (Robberies_Table INNER JOIN Branches_Table ON Robberies_Table.BranchCode = Branches_Table.BranchCode);";

                P 1 Reply Last reply
                0
                • U User3490

                  IN C# THE QUERY I WRITE IS LIKE THIS : string Cmd = "SELECT * FROM (Robberies_Table INNER JOIN Branches_Table ON Robberies_Table.BranchCode = Branches_Table.BranchCode);"; AND WHEN I RUN THE PROGRAM NOW ONLY THE RECORD IS UNDER THE BRANCHNAME IT APPEAR IN SCREEN THE DATA OF ROBBERIES TABLE DON'T SHOW ME IF I WRITE THE SAME THAT IS IN MY DATABASE QUERY C# SHOW ME MY CRYSTAL REPORT EMPTY SO I WRITE AS ABOVE AND HAS THE ABOVE ERROR DIDN'T SHOW ANYTHING: ------------------------ string Cmd = "SELECT Robberies_Table.BankName, Robberies_Table.Region, Robberies_Table.BranchCode, Robberies_Table.[Date], Robberies_Table.Ammount,Robberies_Table.Description, Robberies_Table.Robbery_ID, Robberies_Table.[Year], Branches_Table.BranchName FROM (Robberies_Table INNER JOIN Branches_Table ON Robberies_Table.BranchCode = Branches_Table.BranchCode);";

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #8

                  I don't know how many different ways I can put this, but try running the same query that you issue in your C# code in the SQL table. You can't run different queries and then expect them to be the same.

                  I was brought up to respect my elders. I don't respect many people nowadays.
                  CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                  U 1 Reply Last reply
                  0
                  • P Pete OHanlon

                    I don't know how many different ways I can put this, but try running the same query that you issue in your C# code in the SQL table. You can't run different queries and then expect them to be the same.

                    I was brought up to respect my elders. I don't respect many people nowadays.
                    CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                    U Offline
                    U Offline
                    User3490
                    wrote on last edited by
                    #9

                    MY DATABASE IS ACCESS NOT SQL AND I OBSERVE THAT HAS MANY DIFFERENCES IN THE WAY YOU WRITE THE QUERY. BUT ITS OK I WILL TRY MORE AND I WILL FIND THE SOLUTION ANYWAY... THANK YOU :)

                    R 1 Reply Last reply
                    0
                    • U User3490

                      why is my query wrong at FROM ? i want to connect two tables so i can get some specific data but c# appear error. try { //Set the command string string Cmd = "SELECT * FROM Robberies_Table JOIN Branches_Table ON Robberies_Table.BranchCode =Branches_Table.BranchCode ;"; //create new new connection to the database OleDbConnection conn = new OleDbConnection(ConnectionString); //create new data adapter OleDbDataAdapter Adapter = new OleDbDataAdapter(Cmd, conn); //create new command builder OleDbCommandBuilder CmdBuilder = new OleDbCommandBuilder(Adapter); dTable = new DataTable(); Adapter.Fill(dTable); conn.Close(); } catch (Exception e) { MessageBox.Show(e.ToString()); } //return the search results on a datatable return dTable; }

                      R Offline
                      R Offline
                      ROHIT SRIVASTAVA
                      wrote on last edited by
                      #10

                      Would you plaese remove the * and write the columns that you want to access after joining both the table like-- select column1,column2 from (table1 JOIN table2 where.....)

                      1 Reply Last reply
                      0
                      • U User3490

                        MY DATABASE IS ACCESS NOT SQL AND I OBSERVE THAT HAS MANY DIFFERENCES IN THE WAY YOU WRITE THE QUERY. BUT ITS OK I WILL TRY MORE AND I WILL FIND THE SOLUTION ANYWAY... THANK YOU :)

                        R Offline
                        R Offline
                        Ravi Bhavnani
                        wrote on last edited by
                        #11

                        Please don't SHOUT.  It's not polite. :) /ravi

                        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                        U 1 Reply Last reply
                        0
                        • R Ravi Bhavnani

                          Please don't SHOUT.  It's not polite. :) /ravi

                          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                          U Offline
                          U Offline
                          User3490
                          wrote on last edited by
                          #12

                          I am so sorry if i make you to understand like this. I say this, because i felt that i had made you to feel tired about my problem with query in c# so i had preferred to release you from this, because maybe the problem didn't be the query but something that affect it. i am sorry again ..

                          R 1 Reply Last reply
                          0
                          • U User3490

                            I am so sorry if i make you to understand like this. I say this, because i felt that i had made you to feel tired about my problem with query in c# so i had preferred to release you from this, because maybe the problem didn't be the query but something that affect it. i am sorry again ..

                            R Offline
                            R Offline
                            Ravi Bhavnani
                            wrote on last edited by
                            #13

                            No worries! :) /ravi

                            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups