Load all db tables in treeview??[Resolved]
I couldn't figure out how to do this ? I have only VB.NET version ! I've been trying to convert it for a while but to no avail . anyone show me how plz ?
VB Code:
'TreeView
Public Overloads Shared Sub LoadTables(ByVal TreView As TreeView)
OpenDB.OpenDB()
Dim Tables As DataTable = MyConnection.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Tables, _
New Object() {Nothing, Nothing, Nothing, "TABLE"})
CloseDB.CloseDB()
If Tables.Rows.Count > 0 Then
TreView.BeginUpdate()
'add tables as child nodes
Dim dr As DataRow
For Each dr In Tables.Rows
'you can add icons here if you want
TreView.Nodes.Add(New TreeNode(dr("TABLE_NAME")))
Next
TreView.EndUpdate()
End If
Tables = Nothing
End Sub
C#
Code:
//TreeView
public static void LoadTables (System.Windows.Forms.TreeView TreView)
{
OpenDB.OpenDB1() ;
DataTable Tables = MyConnection().GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables,new object[]{null,null,null,"TABLE"});
CloseDB.CloseDB1();
if (Tables.Rows.Count > 0 ){
TreView.BeginUpdate();
foreach (DataRow dr in Tables.Rows ) {
TreView.Nodes.Add(new TreeNode (dr(("TABLE_NAME"))));
TreView.EndUpdate ();
}
Tables=null;
}
}
This code keeps throwing an error says :
Class1.cs(72): 'dr' denotes a 'variable' where a 'method' was expected
I tried all possible ways but I don't get it to work ? Is my code correct ??
btw , I can load tables in listbox , combobox , checkedlistbox !
Thanks