473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Odbc;

namespace TableFieldsInfo
{
class Program
{
static void Main(string[] args)
{
string cnString =
"DSN=MyDsn;SERVER=SERVER1;UID=ME;PWD=;DATABASE=TES TDB";

OdbcConnection cn = new OdbcConnection();
cn.ConnectionString = cnString;
cn.Open();

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

OdbcDataReader dr =
cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

DataTable dt = dr.GetSchemaTable();

DisplayFields(dt);
}

private static void DisplayFields(System.Data.DataTable table)
{
foreach (System.Data.DataRow row in table.Rows)
{
foreach (System.Data.DataColumn col in table.Columns)
{
Console.WriteLine("{0} = {1}", col.ColumnName,
row[col]);
}
Console.WriteLine("===========================");
}
}
}
}

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 2112
See this KB

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


"Gerrit" <gs*************@hotmail.comwrote in message
news:d0***************************@news.chello.nl. ..
Hello,

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

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Odbc;

namespace TableFieldsInfo
{
class Program
{
static void Main(string[] args)
{
string cnString =
"DSN=MyDsn;SERVER=SERVER1;UID=ME;PWD=;DATABASE=TES TDB";

OdbcConnection cn = new OdbcConnection();
cn.ConnectionString = cnString;
cn.Open();

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

OdbcDataReader dr =
cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

DataTable dt = dr.GetSchemaTable();

DisplayFields(dt);
}

private static void DisplayFields(System.Data.DataTable table)
{
foreach (System.Data.DataRow row in table.Rows)
{
foreach (System.Data.DataColumn col in table.Columns)
{
Console.WriteLine("{0} = {1}", col.ColumnName,
row[col]);
}
Console.WriteLine("===========================");
}
}
}
}

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.netschreef in bericht
news:%2****************@TK2MSFTNGP03.phx.gbl...
See this KB

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


"Gerrit" <gs*************@hotmail.comwrote in message
news:d0***************************@news.chello.nl. ..
>Hello,

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

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Odbc;

namespace TableFieldsInfo
{
class Program
{
static void Main(string[] args)
{
string cnString =
"DSN=MyDsn;SERVER=SERVER1;UID=ME;PWD=;DATABASE=TE STDB";

OdbcConnection cn = new OdbcConnection();
cn.ConnectionString = cnString;
cn.Open();

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

OdbcDataReader dr =
cmd.ExecuteReader(CommandBehavior.CloseConnection );

DataTable dt = dr.GetSchemaTable();

DisplayFields(dt);
}

private static void DisplayFields(System.Data.DataTable table)
{
foreach (System.Data.DataRow row in table.Rows)
{
foreach (System.Data.DataColumn col in table.Columns)
{
Console.WriteLine("{0} = {1}", col.ColumnName,
row[col]);
}
Console.WriteLine("===========================");
}
}
}
}

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.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Odbc;

namespace TableFieldsInfo
{
class Program
{
static void Main(string[] args)
{
string cnString =
"DSN=MyDsn;SERVER=SERVER1;UID=ME;PWD=;DATABASE=TES TDB";

OdbcConnection cn = new OdbcConnection();
cn.ConnectionString = cnString;
cn.Open();

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

OdbcDataReader dr =
cmd.ExecuteReader(CommandBehavior.CloseConnection) ;

DataTable dt = dr.GetSchemaTable();

DisplayFields(dt);
}

private static void DisplayFields(System.Data.DataTable table)
{
foreach (System.Data.DataRow row in table.Rows)
{
foreach (System.Data.DataColumn col in table.Columns)
{
Console.WriteLine("{0} = {1}", col.ColumnName,
row[col]);
}
Console.WriteLine("===========================");
}
}
}
}

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 connectionstring for oledb connection, so I look further in that
direction.

--

www.gsnel.nl
"Truong Hong Thi" <th*****@gmail.comschreef in bericht
news:11**********************@m73g2000cwd.googlegr oups.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.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Odbc;

namespace TableFieldsInfo
{
class Program
{
static void Main(string[] args)
{
string cnString =
"DSN=MyDsn;SERVER=SERVER1;UID=ME;PWD=;DATABASE=TE STDB";

OdbcConnection cn = new OdbcConnection();
cn.ConnectionString = cnString;
cn.Open();

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

OdbcDataReader dr =
cmd.ExecuteReader(CommandBehavior.CloseConnection );

DataTable dt = dr.GetSchemaTable();

DisplayFields(dt);
}

private static void DisplayFields(System.Data.DataTable table)
{
foreach (System.Data.DataRow row in table.Rows)
{
foreach (System.Data.DataColumn col in table.Columns)
{
Console.WriteLine("{0} = {1}", col.ColumnName,
row[col]);
}
Console.WriteLine("===========================");
}
}
}
}

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.googlegr oups.com...
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
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
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,...
7
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...
4
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...
3
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...
6
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? ...
1
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...
7
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...
2
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.