Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Get a database table properties
WhatsApp
Mahesh Chand
4y
34.2k
0
2
100
Article
TableInfo_v1.zip
This program displays your table properties such as its column names, types, and column properties. I have used a database "mcTest.mdb" which has a table called 'Developer'. You can download this attached database and change the path of the database according to your location.
Explanation
I have used ADODataSetCommand, DataSet, DataTable, and DataColumn classes to do so. See my forthcoming tutorial on ADO.NET for more details of these classes.
private
void
Form1_Load(
object
sender, System.EventArgs e) {
string
strDSN =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\mcTest.MDB"
;
string
strSQL =
"SELECT * FROM Developer"
;
// create Objects of ADOConnection and ADOCommand
OleDbConnection myConn =
new
OleDbConnection(strDSN);
OleDbDataAdapter myCmd =
new
OleDbDataAdapter(strSQL, myConn);
myConn.Open();
DataSet dtSet =
new
DataSet();
myCmd.Fill(dtSet,
"Developer"
);
DataTable dt = dtSet.Tables[0];
listBox1.Items.Add(
"Field Name DataType Unique AutoIncrement AllowNull"
);
listBox1.Items.Add(
"================================="
);
foreach
(DataColumn dc
in
dt.Columns) {
listBox1.Items.Add(dc.ColumnName +
" , "
+ dc.DataType +
" ,"
+ dc.Unique +
" ,"
+ dc.AutoIncrement +
" ,"
+ dc.AllowDBNull);
}
}
How to Run?
Download source code and database zip files and unzip them.
Change the database path in this string. "Provider=Microsoft.JET.OLEDB.4.0;data source=C:\\Mahesh\\mcb.mdb");
Run the application
ADO.NET
ADODataSetCommand
C#
column names
database
DataColumn
DataColumn and DataTable properties
DataColumn classes
DataTable
Get a database table properties
Up Next
Ebook Download
View all
Printing in C# Made Easy
Read by 22.4k people
Download Now!
Learn
View all
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.
Membership not found