SqlConnection scon=new SqlConnection(constr);
scon.Open();
SqlDataAdapter sda=new SqlDataAdapter("SELECT MA001,MA002,MA003 FROM DSCSYS.dbo.DSCMA",scon);
SqlCommandBuilder scb=new SqlCommandBuilder(sda);
DataSet ds=new DataSet();
sda.Fill(ds,"DSCMA");
DataColumn[] keys=new DataColumn[1];
MessageBox.Show(ds.Tables[0].TableName);
keys[0]=ds.Tables["DSCMA"].Columns["MA001"];
ds.Tables[0].PrimaryKey=keys;
这是我设置主键的代码,我的表MA001是主键,没有重复的。但运行时出错为:
未处理的“System.ArgumentException”类型的异常出现在 system.data.dll 中。
其他信息: These columns dont currently have unique values.
请问是怎么回事,要怎么处理?
......
sda.FillSchema(ds,System.Data.SchemaType.Mapped);
sda.Fill(ds,"DSCMA");
......
还有PrimaryKey属性好像只有在数据表没有数据时设置才有效。
MARK , 提示已很明显,楼主仔细找
dt.CaseSensitive=true;