What is wrong with the following code?

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"];

}
 
D

David Sceppa

I believe the problem lies in how you're constructing the
DataRelation. It looks like you have the parameters out of order. The
first DataColumn should be the parent (Jobs.JobID) and the second
DataColumn should be the child (Employees.JobID).

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2004 Microsoft Corporation. All rights reserved.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top