Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 439
  • Last Modified:

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
0
jemigossaye
Asked:
jemigossaye
1 Solution
 
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
 
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now