public int SetData(System.Data.DataTable dt)
{
DataTable dtPrint = new DataTable();
dtPrint = dt.Copy();
dtPrint.PrimaryKey = null;//dt是传进来的,有主键。想把主键取消,但是没有找到相关的方法,就给置成null。
dtPrint.TableName = "dtPrint"; 。
for (int j = 0; j < pageBlankRow; j++)
{
dr = dtPrint.NewRow();
//这个位置需要插入空白的行,但是报错提示的意思就是“主键的列不能为空”
dtPrint.Rows.InsertAt(dr, rowNum + blankRowCount);
}
。
}如何在datatable中取消主键,插入空白行那。谢谢各位大侠了啊。
{
DataTable dtPrint = new DataTable();
dtPrint = dt.Copy();
dtPrint.PrimaryKey = null;//dt是传进来的,有主键。想把主键取消,但是没有找到相关的方法,就给置成null。
dtPrint.TableName = "dtPrint"; 。
for (int j = 0; j < pageBlankRow; j++)
{
dr = dtPrint.NewRow();
//这个位置需要插入空白的行,但是报错提示的意思就是“主键的列不能为空”
dtPrint.Rows.InsertAt(dr, rowNum + blankRowCount);
}
。
}如何在datatable中取消主键,插入空白行那。谢谢各位大侠了啊。
//....
dc[0].AllowDBNull = true;
dc[0].Unique = false; dt.PrimaryKey = null;
在你传过来的参数dt中,dt.Columns["主键的列"].AllowDBNull = false;
所以在你执行取消主键列后,还需要手动地将dt.Columns["主键的列"].AllowDBNull = true;
这样就不会提示错误了.