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