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. WPF
  4. SQL query = How to get database table name only in to datagrid

SQL query = How to get database table name only in to datagrid

Scheduled Pinned Locked Moved WPF
databasetutorialquestion
4 Posts 3 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 Can someone please tell me, what is the database SQL query to display the name of the table only in to datagrid... kind regards roni

    M 1 Reply Last reply
    0
    • L LAPEC

      hello Everyone Can someone please tell me, what is the database SQL query to display the name of the table only in to datagrid... kind regards roni

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Presumably you are using sql server - look into the sys.sysobject and the system views, all the information is in there. The system views were set up in 2005 (I think) specifically for this.

      Never underestimate the power of human stupidity RAH

      L 1 Reply Last reply
      0
      • M Mycroft Holmes

        Presumably you are using sql server - look into the sys.sysobject and the system views, all the information is in there. The system views were set up in 2005 (I think) specifically for this.

        Never underestimate the power of human stupidity RAH

        L Offline
        L Offline
        LAPEC
        wrote on last edited by
        #3

        Hi Mycroft Holmes Actually I'm using Microsoft access 2007 database, I'm not using the SQL Server, maybe you can have a look at the code below and tell me what am I doing wrong...

        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();
                }
            }
        

        Basically what I'm trying to do is to display the database table name in to datagrid, but i can't figur out the SQL query how to do it, maybe you can help me and solve it... kind regards Roni

        P 1 Reply Last reply
        0
        • L LAPEC

          Hi Mycroft Holmes Actually I'm using Microsoft access 2007 database, I'm not using the SQL Server, maybe you can have a look at the code below and tell me what am I doing wrong...

          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();
                  }
              }
          

          Basically what I'm trying to do is to display the database table name in to datagrid, but i can't figur out the SQL query how to do it, maybe you can help me and solve it... kind regards Roni

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

          What on earth does this have to do with WPF or Silverlight? You are aware that we have a database forum where you could ask this question aren't you?

          *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

          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