|
Mangore75 wrote: I want to create a code to show me the name of Table and Field in the DB
Which table? Any table[^]?
What have you tried so far?
Bastard Programmer from Hell
|
|
|
|
|
The Table in the DB(MyDB) which connection to my project :
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source =" & Application.StartupPath & "\MyDB.mdb")
-Nothing
|
|
|
|
|
Which table? The database will have multiple tables, and I already posted the query that returns a list of all tables in that database.
What are you trying to achieve? Do you want to know which tables are in that database, or are you trying something else?
Bastard Programmer from Hell
|
|
|
|
|
I'm sorry I didn't know how to use this query in vb.net...
|
|
|
|
|
Are you having trouble with that specific query, or with queries in general in VB?
Bastard Programmer from Hell
|
|
|
|
|
Mangore75 wrote: I want to create a code to show me the name of Table and Field in the DB
You go right ahead and do that. Let us know how it goes.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
I tried this way but nothing happen:
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source =" & Application.StartupPath & "\MyDB.mdb")
conn.Open()
Dim dt As DataTable
dt = conn.GetSchema("Tables")
MsgBox(dt)
conn.Close()
|
|
|
|
|
Mangore75 wrote: but nothing happen
You press F5, and then you either get an exception, or a result. If you executed the code you have now, you get a MessageBox with the text "Tables". That's because the "dt" variable contains a DataTable object with tables, and if you try to show it with a MsgBox , you'll see a .ToString() version of the object.
Click on the gutter in the right on the line that says "MsgBox" and put a breakpoint there. Run your code, and hover your mouse over the "dt" variable when the yellow line hits the breakpoint.
This code worked for me;
Imports System.Data.OleDb
Module Module1
Sub Main()
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source =""C:\Users\Eddy\Desktop\NWind.mdb""")
conn.Open()
Dim dt As DataTable
dt = conn.GetSchema("TABLES")
conn.Close()
For Each row As DataRow In dt.Rows
For Each item As Object In row.ItemArray
Console.Write(item)
Next
Console.WriteLine()
Next
Console.WriteLine(dt)
Console.ReadKey()
End Sub
End Module
It's easier if you learn it from a book.
Bastard Programmer from Hell
|
|
|
|
|
I made it your code like this but didn't work . it showed me msgbox but there is no any of name tables.
conn.Open()
Dim dt As DataTable
dt = conn.GetSchema("TABLES")
conn.Close()
For Each row As DataRow In dt.Rows
For Each item As Object In row.ItemArray
MsgBox(item.ToString)
Next
Next
MsgBox(dt.ToString)
|
|
|
|
|
Mangore75 wrote: it showed me msgbox but there is no any of name tables.
That's why I explained how to use the debugger. Seriously, put the cursor on the line that contains the MessageBox , hit the F9 key and F5 . Once the IDE shows up again, your application will be halted on the line with the breakpoint, allowing you to inspect the contents of the variable. That's a lot more effective that looking at things through a MsgBox .
On to your problem; the code should work. Download the Northwind[^]-example and test the code below (with the complete path to your database);
Dim dt As DataTable
Using con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source =""C:\Users\Eddy\Desktop\NWind.mdb""")
con.Open()
dt = con.GetSchema("TABLES")
End Using
For Each row As DataRow In dt.Rows
Console.WriteLine(row("TABLE_NAME"))
Next
Console.WriteLine()
Bastard Programmer from Hell
|
|
|
|
|
There are a couple of ways to do that. Here is some code I have, it differs from the other approach in that it doesn't use MSysObjects, instead it uses GetSchema(). As it is using C#, you may have to transpose it to your language though.
public override List<string> GetTableNames(bool all) {
using (OleDbConnection con=new OleDbConnection(connectionString)) {
con.Open();
DataTable dt=con.GetSchema("Tables");
List<string> tableNames=new List<string>();
foreach (DataRow row in dt.Rows) {
string tableName=(string)row["TABLE_NAME"];
if (!all) {
string tableNameLC=tableName.ToLower();
if (tableNameLC.StartsWith("msys")) continue;
if (tableNameLC.StartsWith("qry")) continue;
if (tableNameLC.StartsWith("query")) continue;
if (tableNameLC.StartsWith("qyr")) continue;
if (tableNameLC.EndsWith("_conflict")) continue;
}
tableNames.Add(tableName);
}
return tableNames;
}
}
This may interest you as well:
public override DataTable GetTableDescriptions() {
using (OleDbConnection con=new OleDbConnection(connectionString)) {
con.Open();
return con.GetSchema("TABLES");
}
}
And this gives you all possible information on the columns:
public DataTable GetFieldDescriptions(string tableName) {
using (OleDbConnection con=new OleDbConnection(connectionString)) {
con.Open();
return con.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] {null, null, tableName, null });
}
}
|
|
|
|
|
I want to learn about Project of VB.Net.
|
|
|
|
|
Have you considered a good book? You could also try the Beginners Portal[^] on MSDN.
Bastard Programmer from Hell
|
|
|
|
|
Eddy Vluggen wrote: Have you considered a good book?
Reading a good book rather than learning VB.NET, good suggestion!
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
Pratchett is always a good suggestion
|
|
|
|
|
you can contact me on ag99110011@gmail.com for learning vb.net programming.
ag99110011
|
|
|
|
|
|
thank's Clark for the link..
i'd love to start learning vb.net from the beginning..
|
|
|
|
|
|
Hi mates,
I have a website and my boss wants to have 3 language.
In a login page there will be a dropdown list (English,Japanese,Chinese)
after the password box.
The problem is, I don't know how to code it,
anyone have idea would be much appreciated.
They want to put in excel file.
So that they can easily add/modify a word or sentence.
I've read and search in google but result is only using
the .resx files.
Thanks in advance.
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
C#Coudou wrote: I've read and search in google but result is only using the .resx files.
That's the easiest way; see the topic Multilingual content in Web Pages[^].
Making an interface to Excel will be extra work, complicating the issue. I suggest you start by introducing multilingual content, and worry about editing the languages later on.
Bastard Programmer from Hell
|
|
|
|
|
|
I am using Microsoft.Office.Interop.Excel to open, read, and write to an excel workbook in VB.net. How do I figure out if a workbook is already open?
|
|
|
|
|
Maybe this might help ...
Dim gExcelApp As New Excel.Application
Dim i As Integer
gExcelApp.Visible = True
gExcelApp.WindowState = Excel.XlWindowState.xlNormal
gExcelApp.Workbooks.Open("C:\Temp\Test.xls", , True)
For i = 1 To gExcelApp.Workbooks.Count
If (gExcelApp.Workbooks(i).Name.Equals("test.xls")) Then
Debug.Print("Already open")
End If
Next
|
|
|
|
|
Thanks David. This worked for me when the workbook was open with the current excel app. Is there a way I can find out if it is open under another excel app? Put another way, is there a way I can find all running excel apps?
|
|
|
|