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. Database & SysAdmin
  3. Database
  4. What is database SQL query to display the name of the table only in to datagrid?

What is database SQL query to display the name of the table only in to datagrid?

Scheduled Pinned Locked Moved Database
databasecsharpquestionwpfhelp
4 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.
  • L Offline
    L Offline
    LAPEC
    wrote on last edited by
    #1

    Hello Everyone I have created a WPF project (C# language) and I also have a MS Access 2007 database. I'm trying to display the database table name in to datagrid, but i can't figur out the SQL query how to do it. The code below that I wrote it's not correct I think maybe someone can help me please and solve it...

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
    string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
    string CmdString = string.Empty;

            using (OleDbConnection myConnection = new OleDbConnection(ConString))
            {
                CmdString = "SELECT FoodMenu FROM MSysObjects WHERE (FoodMenu Not Like 'MSys\*') AND (Type In (1,4,6)) ORDER BY FoodMenu";
    
                OleDbCommand comm = new OleDbCommand(CmdString, myConnection);
                OleDbDataAdapter sda = new OleDbDataAdapter(comm);
                myConnection.Open();
                DataTable dt = myConnection.GetSchema("Tables");   //Get list of user tables  
                foreach (DataRow dataRow in dt.Rows)
                {
                    DataGridMenuTables.Items.Add(dataRow\["FoodMenu"\].ToString().Trim());
                    //DataGridMenuTables.ItemsSource = dt.DefaultView;
                }
                //myConnection.Close();
            }
        }
    

    Kind regards Roni

    P V 2 Replies Last reply
    0
    • L LAPEC

      Hello Everyone I have created a WPF project (C# language) and I also have a MS Access 2007 database. I'm trying to display the database table name in to datagrid, but i can't figur out the SQL query how to do it. The code below that I wrote it's not correct I think maybe someone can help me please and solve it...

      private void Window_Loaded(object sender, RoutedEventArgs e)
      {
      string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
      string CmdString = string.Empty;

              using (OleDbConnection myConnection = new OleDbConnection(ConString))
              {
                  CmdString = "SELECT FoodMenu FROM MSysObjects WHERE (FoodMenu Not Like 'MSys\*') AND (Type In (1,4,6)) ORDER BY FoodMenu";
      
                  OleDbCommand comm = new OleDbCommand(CmdString, myConnection);
                  OleDbDataAdapter sda = new OleDbDataAdapter(comm);
                  myConnection.Open();
                  DataTable dt = myConnection.GetSchema("Tables");   //Get list of user tables  
                  foreach (DataRow dataRow in dt.Rows)
                  {
                      DataGridMenuTables.Items.Add(dataRow\["FoodMenu"\].ToString().Trim());
                      //DataGridMenuTables.ItemsSource = dt.DefaultView;
                  }
                  //myConnection.Close();
              }
          }
      

      Kind regards Roni

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      LAPEC wrote:

      DataTable dt = myConnection.GetSchema("Tables"); //Get list of user tables

      That should work.

      LAPEC wrote:

      //DataGridMenuTables.ItemsSource = dt.DefaultView;

      Do you mean DataSource?

      LAPEC wrote:

      dataRow["FoodMenu"].ToString()

      It's already a string, don't use ToString, just cast it ((string) dataRow["FoodMenu"]).Trim()

      1 Reply Last reply
      0
      • L LAPEC

        Hello Everyone I have created a WPF project (C# language) and I also have a MS Access 2007 database. I'm trying to display the database table name in to datagrid, but i can't figur out the SQL query how to do it. The code below that I wrote it's not correct I think maybe someone can help me please and solve it...

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
        string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
        string CmdString = string.Empty;

                using (OleDbConnection myConnection = new OleDbConnection(ConString))
                {
                    CmdString = "SELECT FoodMenu FROM MSysObjects WHERE (FoodMenu Not Like 'MSys\*') AND (Type In (1,4,6)) ORDER BY FoodMenu";
        
                    OleDbCommand comm = new OleDbCommand(CmdString, myConnection);
                    OleDbDataAdapter sda = new OleDbDataAdapter(comm);
                    myConnection.Open();
                    DataTable dt = myConnection.GetSchema("Tables");   //Get list of user tables  
                    foreach (DataRow dataRow in dt.Rows)
                    {
                        DataGridMenuTables.Items.Add(dataRow\["FoodMenu"\].ToString().Trim());
                        //DataGridMenuTables.ItemsSource = dt.DefaultView;
                    }
                    //myConnection.Close();
                }
            }
        

        Kind regards Roni

        V Offline
        V Offline
        vvashishta
        wrote on last edited by
        #3

        The simplest way is to create a Stored Procedure and put below mentioned SQL Query to fetch the list of tables in database.. then Bind those records to a DataGrid in C#. SQL Query is: SELECT * FROM information_schema.tables

        - Happy Coding - Vishal Vashishta

        L 1 Reply Last reply
        0
        • V vvashishta

          The simplest way is to create a Stored Procedure and put below mentioned SQL Query to fetch the list of tables in database.. then Bind those records to a DataGrid in C#. SQL Query is: SELECT * FROM information_schema.tables

          - Happy Coding - Vishal Vashishta

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I think he's using Microsoft Access, not Sql Server :rolleyes:

          Bastard Programmer from Hell :suss:

          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