关键是在之前要填充这些信息
myCommand.FillSchema(ds,SchemaType.Mapped,"myTable");
myCommand.Fill(ds,"myTable");DataColumn[] objColumn;
objColumn = ds.Tables["myTable"].PrimaryKey;
for (int i = 0; i <= objColumn.Length - 1; i++)
{
Label3.Text += (objColumn[i].ColumnName + ";");
}
myCommand.FillSchema(ds,SchemaType.Mapped,"myTable");
myCommand.Fill(ds,"myTable");DataColumn[] objColumn;
objColumn = ds.Tables["myTable"].PrimaryKey;
for (int i = 0; i <= objColumn.Length - 1; i++)
{
Label3.Text += (objColumn[i].ColumnName + ";");
}
解决方案 »
- 求rtf编辑器
- 我用datagrid来显示数据库中的数据,既可以点击列标题来排序,又可以分页 现在的问题是,当我在某页单击列标题排序后,点击下一页时的datagrid中的数据没有排序了。
- 类的继承重载问题,出错:no suitable method found to override
- 怎样把asp.net2.0生成dll文件
- 我在ASP.NET里面打开WorD老是拒绝访问,请问你们有没有遇到过类似的问题?
- 将asp移植到win2003上后的奇怪问题
- 请高手指点几个asp.net的问题,感激不尽!在asp.net中怎样锁定数据库中的记录,有几种方式?
- 什么东东有viewstate属性呀
- aspx页面能调用DLL里面的资源文件吗(就象CS程序一样)?
- 请问怎么删除DataTable中的相同的行?
- 有哪个在网上成功的找到工作?
- 在线求关闭窗口问题!各位大虾来看看:
// Create the array for the columns.
DataColumn[] colArr;
colArr = myTable.PrimaryKey;
// Get the number of elements in the array.
Console.WriteLine("Column Count: " + colArr.Length);
for(int i = 0; i < colArr.Length; i++){
Console.WriteLine(colArr[i].ColumnName + colArr[i].DataType);
}
}
private void SetPrimaryKeys(){
// Create a new DataTable and set two DataColumn objects as primary keys.
DataTable myTable = new DataTable();
DataColumn[] keys = new DataColumn[2];
DataColumn myColumn;
// Create column 1.
myColumn = new DataColumn();
myColumn.DataType = System.Type.GetType("System.String");
myColumn.ColumnName= "FirstName";
// Add the column to the DataTable.Columns collection.
myTable.Columns.Add(myColumn);
// Add the column to the array.
keys[0] = myColumn;
// Create column 2 and add it to the array.
myColumn = new DataColumn();
myColumn.DataType = System.Type.GetType("System.String");
myColumn.ColumnName = "LastName";
myTable.Columns.Add(myColumn);
// Add the column to the array.
keys[1] = myColumn;
// Set the PrimaryKeys property to the array.
myTable.PrimaryKey = keys;
}