C
cglanvi
Can anyone tell me what is wrong with the following code? I get an error
message that states: An unhandled exception of type system.argumentexception
occurred in system.data.dll these columns don't currently have unique
values
But the values are unique. They are the keys values in the database. The
code I am using is the following:
private void button1_Click(object sender, System.EventArgs e)
{
SqlConnection cn = new SqlConnection( "workstation id=THENAME;packet
size=4096;integrated security=SSPI;data source=.;persist security
info=False;initial catalog=pubs");
SqlCommand cmd = new SqlCommand( "select * from employee", cn );
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill( ds, "employee");
cmd.CommandText = "select * from jobs";
da.Fill(ds, "jobs");
DataRelation rel = new DataRelation ( "mydatarelation",
ds.Tables["employee"].Columns["job_id"],
ds.Tables["jobs"].Columns["job_id"] );
ds.Relations.Add(rel);
dataGrid1.DataSource = ds.Tables["employee"];
}
message that states: An unhandled exception of type system.argumentexception
occurred in system.data.dll these columns don't currently have unique
values
But the values are unique. They are the keys values in the database. The
code I am using is the following:
private void button1_Click(object sender, System.EventArgs e)
{
SqlConnection cn = new SqlConnection( "workstation id=THENAME;packet
size=4096;integrated security=SSPI;data source=.;persist security
info=False;initial catalog=pubs");
SqlCommand cmd = new SqlCommand( "select * from employee", cn );
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill( ds, "employee");
cmd.CommandText = "select * from jobs";
da.Fill(ds, "jobs");
DataRelation rel = new DataRelation ( "mydatarelation",
ds.Tables["employee"].Columns["job_id"],
ds.Tables["jobs"].Columns["job_id"] );
ds.Relations.Add(rel);
dataGrid1.DataSource = ds.Tables["employee"];
}