Re: What is wrong with the following code?
From: William Ryan eMVP (dotnetguru_at_comcast.nospam.net)
Date: 06/08/04
- Next message: Roy Fine: "Re: Oracle scheme"
- Previous message: William Ryan eMVP: "Re: select distinct in rowfilter"
- In reply to: John Smith: "What is wrong with the following code?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 7 Jun 2004 21:23:51 -0400
I'm assuming the exception is after the Fill right? That indicates that one
of those columns has some dup values or that the key can't be made for some
reason. Can you double check that there aren't any dups and that the keys
are properly in place. Also, try catch the relation.Add and see if the
exception messsage can give you some more info.
Also, set the column's Unique property to true for each of the columns
before adding the relation.
-- W.G. Ryan MVP Windows - Embedded http://forums.devbuzz.com http://www.knowdotnet.com/dataaccess.html http://www.msmvps.com/williamryan/ "John Smith" <someone@microsoft.com> wrote in message news:OZYalHOTEHA.2372@TK2MSFTNGP11.phx.gbl... > 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"]; > > } > >
- Next message: Roy Fine: "Re: Oracle scheme"
- Previous message: William Ryan eMVP: "Re: select distinct in rowfilter"
- In reply to: John Smith: "What is wrong with the following code?"
- Messages sorted by: [ date ] [ thread ]