473,386 Members | 1,710 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,386 software developers and data experts.

PrimaryKey Does Not Returns KeyColumns

Hi,
I want to determine column names of Primary Key Columns of a SQL Server
Table. To do this I've found following example in MSDN under PrimaryKey
property of DataTable. I've add some lines of code to initialize table
object and rest is as it

dim table as new datatable()
dim adp as new sqlclient.sqldataadapter("Select * from emp",cn)
adp.fill (table)
Dim columns() As DataColumn
columns = table.PrimaryKey
' Get the number of elements in the array.
Console.WriteLine("Column Count: " & columns.Length.ToString())
Dim i As Integer
For i = 0 To columns.GetUpperBound(0)
Console.WriteLine(columns(i).ColumnName &
columns(i).DataType.ToString())
Next i

according to msdn columns() arrary should contains primarykey column
information of emp table. But the above program not return any column
information.

so, How can we determine the column name of PrimaryKey of a sql server
table.?

Indar Bisen

Aug 29 '06 #1
0 1052

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

Similar topics

2
by: alan | last post by:
Hi Does primarykey property on the datatable object always need to be set in your code (for use with datarow.find) or should this be set automatically from your database tables primary key coz this...
0
by: Alan | last post by:
H When adding a new row to a datatables .row collection how do populate the primarykey field , ie SupplierId. Is there a way of retrieving the next available value automatically Thank Alan.
0
by: MuZZy | last post by:
Hi, I wonder if anybody could help me here: i'm trying to set a primary key on a table DataTable dt = new DataTable; FillTable(dt); dt.PrimaryKey = myDataColumn; , and in case if the...
4
by: Lars E | last post by:
Hi all How can i set primarykey to a datatable. This datatable is in a dataset i get from a backend system. My datatable contains several fields, and i want to make the fields "c-custno1",...
2
by: prasannas | last post by:
what is the difference between unique constraint and primarykey and identifiers?
2
by: google | last post by:
How can I find a DataRow in a DataSet by it's PrimaryKey value? This would be similar to an SQL statement such as "SELECT * FROM MyTable WHERE MyIndex = 2"... In the following code I've tried to...
2
chathura86
by: chathura86 | last post by:
public void insertData(String sql) { if(conn != null) { SqlCommand cmd = new SqlCommand(); cmd.Connection = conn ; //setting the connection to sql command ...
1
Fary4u
by: Fary4u | last post by:
Hi, I'm attempting to update a record via the recordset.update method, However, the recordset object is defined and accesses the correct record that I want to update, as I can retrieve field...
0
Fary4u
by: Fary4u | last post by:
Hi, I'm attempting to update a record via the recordset.update method, However, the recordset object is defined and accesses the correct record that I want to update, as I can retrieve field...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.