473,770 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FieldNames and PrimaryKeys in Table

Hello,

I try to display the fieldnames and the primary key of a table, with this
code:

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Data;
using System.Data.Odb c;

namespace TableFieldsInfo
{
class Program
{
static void Main(string[] args)
{
string cnString =
"DSN=MyDsn;SERV ER=SERVER1;UID= ME;PWD=;DATABAS E=TESTDB";

OdbcConnection cn = new OdbcConnection( );
cn.ConnectionSt ring = cnString;
cn.Open();

OdbcCommand cmd = new OdbcCommand();
cmd.Connection = cn;
cmd.CommandText = "SELECT * FROM ARTICLES";

OdbcDataReader dr =
cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);

DataTable dt = dr.GetSchemaTab le();

DisplayFields(d t);
}

private static void DisplayFields(S ystem.Data.Data Table table)
{
foreach (System.Data.Da taRow row in table.Rows)
{
foreach (System.Data.Da taColumn col in table.Columns)
{
Console.WriteLi ne("{0} = {1}", col.ColumnName,
row[col]);
}
Console.WriteLi ne("=========== =============== =");
}
}
}
}

I have tried a lot, but I can only make an OdbcConnection.
With this code, I became a list of the fieldnames, but the field who is the
primary key, the output is: IsKey = false.

Do you have an idea how I can get the primary key of my table?

Thank you very much.
--

www.gsnel.nl
Oct 24 '06 #1
6 2131
See this KB

http://support.microsoft.com/kb/309488


"Gerrit" <gs************ *@hotmail.comwr ote in message
news:d0******** *************** ****@news.chell o.nl...
Hello,

I try to display the fieldnames and the primary key of a table, with this
code:

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Data;
using System.Data.Odb c;

namespace TableFieldsInfo
{
class Program
{
static void Main(string[] args)
{
string cnString =
"DSN=MyDsn;SERV ER=SERVER1;UID= ME;PWD=;DATABAS E=TESTDB";

OdbcConnection cn = new OdbcConnection( );
cn.ConnectionSt ring = cnString;
cn.Open();

OdbcCommand cmd = new OdbcCommand();
cmd.Connection = cn;
cmd.CommandText = "SELECT * FROM ARTICLES";

OdbcDataReader dr =
cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);

DataTable dt = dr.GetSchemaTab le();

DisplayFields(d t);
}

private static void DisplayFields(S ystem.Data.Data Table table)
{
foreach (System.Data.Da taRow row in table.Rows)
{
foreach (System.Data.Da taColumn col in table.Columns)
{
Console.WriteLi ne("{0} = {1}", col.ColumnName,
row[col]);
}
Console.WriteLi ne("=========== =============== =");
}
}
}
}

I have tried a lot, but I can only make an OdbcConnection.
With this code, I became a list of the fieldnames, but the field who is
the
primary key, the output is: IsKey = false.

Do you have an idea how I can get the primary key of my table?

Thank you very much.
--

www.gsnel.nl


Oct 24 '06 #2
I have seen this, but I tried a lot, but I can not make an OleDbConnection
to my Database. That 's the problem I think. Is is possible with an
OdbcConnection do you think?

--

www.gsnel.nl

"sloan" <sl***@ipass.ne tschreef in bericht
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
See this KB

http://support.microsoft.com/kb/309488


"Gerrit" <gs************ *@hotmail.comwr ote in message
news:d0******** *************** ****@news.chell o.nl...
>Hello,

I try to display the fieldnames and the primary key of a table, with this
code:

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Data;
using System.Data.Odb c;

namespace TableFieldsInfo
{
class Program
{
static void Main(string[] args)
{
string cnString =
"DSN=MyDsn;SER VER=SERVER1;UID =ME;PWD=;DATABA SE=TESTDB";

OdbcConnection cn = new OdbcConnection( );
cn.ConnectionSt ring = cnString;
cn.Open();

OdbcCommand cmd = new OdbcCommand();
cmd.Connection = cn;
cmd.CommandText = "SELECT * FROM ARTICLES";

OdbcDataReader dr =
cmd.ExecuteRea der(CommandBeha vior.CloseConne ction);

DataTable dt = dr.GetSchemaTab le();

DisplayFields(d t);
}

private static void DisplayFields(S ystem.Data.Data Table table)
{
foreach (System.Data.Da taRow row in table.Rows)
{
foreach (System.Data.Da taColumn col in table.Columns)
{
Console.WriteLi ne("{0} = {1}", col.ColumnName,
row[col]);
}
Console.WriteLi ne("=========== =============== =");
}
}
}
}

I have tried a lot, but I can only make an OdbcConnection.
With this code, I became a list of the fieldnames, but the field who is
the
>primary key, the output is: IsKey = false.

Do you have an idea how I can get the primary key of my table?

Thank you very much.
--

www.gsnel.nl



Oct 24 '06 #3

Try including CommanBehavior. KeyInfo in the call of ExecuteReader.
If no help, maybe the underlying ODBC driver does not support this
function.

Gerrit wrote:
Hello,

I try to display the fieldnames and the primary key of a table, with this
code:

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Data;
using System.Data.Odb c;

namespace TableFieldsInfo
{
class Program
{
static void Main(string[] args)
{
string cnString =
"DSN=MyDsn;SERV ER=SERVER1;UID= ME;PWD=;DATABAS E=TESTDB";

OdbcConnection cn = new OdbcConnection( );
cn.ConnectionSt ring = cnString;
cn.Open();

OdbcCommand cmd = new OdbcCommand();
cmd.Connection = cn;
cmd.CommandText = "SELECT * FROM ARTICLES";

OdbcDataReader dr =
cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);

DataTable dt = dr.GetSchemaTab le();

DisplayFields(d t);
}

private static void DisplayFields(S ystem.Data.Data Table table)
{
foreach (System.Data.Da taRow row in table.Rows)
{
foreach (System.Data.Da taColumn col in table.Columns)
{
Console.WriteLi ne("{0} = {1}", col.ColumnName,
row[col]);
}
Console.WriteLi ne("=========== =============== =");
}
}
}
}

I have tried a lot, but I can only make an OdbcConnection.
With this code, I became a list of the fieldnames, but the field who is the
primary key, the output is: IsKey = false.

Do you have an idea how I can get the primary key of my table?

Thank you very much.
--

www.gsnel.nl
Oct 25 '06 #4
This is not working, but thanks for your answer. I searched today and I
found a connectionstrin g for oledb connection, so I look further in that
direction.

--

www.gsnel.nl
"Truong Hong Thi" <th*****@gmail. comschreef in bericht
news:11******** **************@ m73g2000cwd.goo glegroups.com.. .
>
Try including CommanBehavior. KeyInfo in the call of ExecuteReader.
If no help, maybe the underlying ODBC driver does not support this
function.

Gerrit wrote:
>Hello,

I try to display the fieldnames and the primary key of a table, with this
code:

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Data;
using System.Data.Odb c;

namespace TableFieldsInfo
{
class Program
{
static void Main(string[] args)
{
string cnString =
"DSN=MyDsn;SER VER=SERVER1;UID =ME;PWD=;DATABA SE=TESTDB";

OdbcConnection cn = new OdbcConnection( );
cn.ConnectionSt ring = cnString;
cn.Open();

OdbcCommand cmd = new OdbcCommand();
cmd.Connection = cn;
cmd.CommandText = "SELECT * FROM ARTICLES";

OdbcDataReader dr =
cmd.ExecuteRea der(CommandBeha vior.CloseConne ction);

DataTable dt = dr.GetSchemaTab le();

DisplayFields(d t);
}

private static void DisplayFields(S ystem.Data.Data Table table)
{
foreach (System.Data.Da taRow row in table.Rows)
{
foreach (System.Data.Da taColumn col in table.Columns)
{
Console.WriteLi ne("{0} = {1}", col.ColumnName,
row[col]);
}
Console.WriteLi ne("=========== =============== =");
}
}
}
}

I have tried a lot, but I can only make an OdbcConnection.
With this code, I became a list of the fieldnames, but the field who is
the
primary key, the output is: IsKey = false.

Do you have an idea how I can get the primary key of my table?

Thank you very much.
--

www.gsnel.nl

Oct 25 '06 #5
Gerrit wrote:
I have seen this, but I tried a lot, but I can not make an OleDbConnection
to my Database. That 's the problem I think. Is is possible with an
OdbcConnection do you think?
Why can you not make an OleDbConnection to your db? Are you getting an
error? What database server are you using and what does your code look
like to create the OleDbConnection ? What does the connection string
look like? Perhaps you can try this site to get the correct connection
string: www.connectionstrings.com

Chris

Oct 26 '06 #6
"Chris Dunaway" <du******@gmail .comschreef in bericht
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Gerrit wrote:
>I have seen this, but I tried a lot, but I can not make an
OleDbConnectio n
to my Database. That 's the problem I think. Is is possible with an
OdbcConnecti on do you think?

Why can you not make an OleDbConnection to your db? Are you getting an
error? What database server are you using and what does your code look
like to create the OleDbConnection ? What does the connection string
look like? Perhaps you can try this site to get the correct connection
string: www.connectionstrings.com

Chris
Hi Chris,

It is a Progress 9.1D database, with OpenLink ODBC driver. There is an OleDb
driver, but we have no licence for that driver. I became a message that the
..lic file could not be found. We have only licence for ODBC. Maybe there are
free other drivers, but I don 't know them.

Gerrit

--

www.gsnel.nl
Oct 26 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11335
by: Josep | last post by:
Hi, I'd like to poll a database and get the table contents, as well as the field names from that table. I've been to php.net but this time I cannot find something helpful. I can get the data, and retrieve it into an array noproblem. I can get the data+fieldnames and put it into a list.
7
3287
by: | last post by:
How do I get to the fieldnames of a table in a recordset? I have a recordset which I output into HTML. And on data from certian columns I need to perform different actions. I would like to use the fieldnames rather then theit sequential numbers, to avoid the need to re-do the code if another field is inserted into the table.
4
2018
by: Little PussyCat | last post by:
Hello, I have had a request, one of our tables is used as a report and I have been asked that all fieldnames for months have dashes in them, like Jan-05 instead of Jan05 and so on... Now what we have is a CURSOR which loops through all values in another table generating these fieldnames, like 'Jan-05', Feb-05' etc.. Then the table definition is modified so these months display as fieldnames.
3
1987
by: Beren | last post by:
Hello, I have an sproc to query a couple of tables, that have the same fieldnames, for example DateCreated. ------------------------------------- Select a.* , b.* From tablea a Join table b On b.keyfield = a.keyfield -------------------------------------
6
4706
by: Miles Keaton | last post by:
Is there a simple way to list fieldnames in a table, from PHP? When on the command-line, I just do \d tablename But how to get the fieldnames from PHP commands? ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly
1
1638
by: meltedown | last post by:
This is a function that returns the names a table field on a pgsql database $skips is simply the field names that will be left out of the result. This function acts differently on two different servers Both servers have PHP Version 4.3.10-10ubuntu4.3 AND PostgreSQL(libpq) Version 7.4.6 On one server, the function acts as expected, returning an array with the field names. On the other server, some of the field names come up 6
7
1874
by: MLH | last post by:
I use this to list table fieldnames to the debug window. Can it be modified to perform similar objective for saved query objects? Would it be best to trash this completely and write a procedure for queries from scratch? Private Sub ListFieldsBttn_Click() '********************************************* ' Prompt user for the table name. List the ' s in the immediate window. '*********************************************
2
1480
by: john | last post by:
In the query builder I made an edit-query in which I have linked table A to table B on IDnr. For every record that matches I want 5 fields of table A to get the values of corresponding fields in table B. I'm able to make this query but only by typing the table B fieldnames in the 'change to'-row. Is there some easy way to drag those fieldnames to that row or another way to make this easier? Thanks, john
0
2724
by: Sebastijan | last post by:
Hi I am interested in DbConnection.GetSchema method of ODP.NET oracle library. When I call (to get primary keys metadata) DataTable pkeys = DbConnection.GetSchema("PrimaryKeys"... foreach (DataRow dr in pkeys.Rows) { string pkTable = dr.ToString();
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10257
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10037
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9904
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.