Error while populating WebDatagrid: 'column' argument cannot be null.

hi all, it might be simple but i don't now what to do. I keep geting this error when i try to relate datasets. here is my code


            SqlConnection StrConn = new SqlConnection(ConfigurationSettings.AppSettings["StrConnectionString"]);
            SqlDataAdapter daUnassignedData = new SqlDataAdapter("select b.company, b.Address, b.City from DMD_Data.dbo.Brokers b", StrConn);
            SqlDataAdapter daUnassignedData1 = new SqlDataAdapter("select l.first_name, l.last_name,l.email_address from INTRANET.dbo.LO_INFORMATION l, DMD_Data.dbo.brokers b where b.brokers_id = l.broker_id", StrConn);
            daUnassignedData.SelectCommand.CommandType = CommandType.Text;
            daUnassignedData1.SelectCommand.CommandType = CommandType.Text;
            DataSet ds = new DataSet();
            daUnassignedData.Fill(ds, "brokers");
            daUnassignedData1.Fill(ds, "los");

            ds.Relations.Clear();
            ds.Relations.Add("rel", ds.Tables["brokers"].Columns["brokers_id"],
                ds.Tables["los"].Columns["broker_id"]);
            this.UltraWebGrid1.DataSource = ds.Tables["brokers"].DefaultView;
            this.UltraWebGrid1.DataBind();
ps. the broker_id in los dataset have null values

thanks
jemigossayeAsked:
Who is Participating?
 
dstanley9Commented:
Your select statements do not include the primary key fields, so those columns are not created in the datasets.

Try:

            SqlDataAdapter daUnassignedData = new SqlDataAdapter("select b.brokers_id, b.company, b.Address, b.City from DMD_Data.dbo.Brokers b", StrConn);
            SqlDataAdapter daUnassignedData1 = new SqlDataAdapter("select l.broker_id, l.first_name, l.last_name,l.email_address from INTRANET.dbo.LO_INFORMATION l, DMD_Data.dbo.brokers b where b.brokers_id = l.broker_id", StrConn);
0
 
Bob LearnedCommented:
Is 'broker_id' a primary key field in each table?  Relationships are built on primary keys, so if you don't have that, then you failed to respect good database design.  The DataSet class validates columns defined for DataRelation objects to make sure that they don't violate any rules for primary keys.

Bob
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.