删除数据表中的主键 [英] Remove primary key in datatable

查看:334
本文介绍了删除数据表中的主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以从数据表中删除主键,还是有什么方法可以先删除"PK"的约束,然后再删除列本身?

is there a way to remove primary key from the datatable Or is there any way to remove the constraints of "PK" first and then remove the column itself?

谢谢!

已更新:

 dtTable.Columns.Add(new System.Data.DataColumn("PRIMARY_KEY", typeof(System.Int32)));
 dtTable.PrimaryKey = new DataColumn[1] { dtTable.Columns["PRIMARY_KEY"] }; // throws an error
 dtTable.Columns["PRIMARY_KEY"].AutoIncrement = true;

推荐答案

您可以使用

DataTable.PrimaryKey = null;

您可以使用删除数据表列

you can delete data table column using

DataTable.Columns.Remove("column name here");

这篇关于删除数据表中的主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆