Connecting Tech Pros Worldwide Forums | Help | Site Map

Strongly typed dataset problem

Newbie
 
Join Date: Jun 2009
Posts: 24
#1: 4 Weeks Ago
Hi,

I am using VS2008 C#. I have manually created a typed dataset "DataSet1" then drag drop a table from an Access db.

I want to populate this "DataSet1" from another dataset "dt" so that I can modify the data into a form suitable for CrystalReport "rpt". The crystal report uses the same "DataSet1" as data source.

If I use this code compiler error says "newDr" in second line is unassigned
DataSet1.ScoreCardTblRow newDr;
newDr.CommunityName = dr["Community"].ToString();

If I use this compiler error says first line needs a type conversion
newDr = ds.ScoreCardTbl.NewRow();
newDr.CommunityName = dr["Community"].ToString();

Anyone know what I should do?

Here is the complete code

Expand|Select|Wrap|Line Numbers
  1.         DbOperation dbOp = new DbOperation();
  2.         DataSet1 ds = new DataSet1();
  3.         CrystalReport1 rpt = new CrystalReport1();
  4.         DataSet1.ScoreCardTblRow newDr;
  5.  
  6.         protected void Page_Load(object sender, EventArgs e)
  7.         {
  8.             DataTable dt;
  9.             string sql = "SELECT * FROM ScoreCard";
  10.  
  11.             dt = dbOp.GetDataSet(sql).Tables[0];
  12.             foreach (DataRow dr in dt.Rows)
  13.             {
  14.                 newDr = ds.ScoreCardTbl.NewRow();
  15.                 newDr.CommunityName = dr["Community"].ToString();
  16.                 rpt.Rows.Add(newDr);
  17.             }
  18.  
  19.         }
  20.  
Denis

tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,791
#2: 4 Weeks Ago

re: Strongly typed dataset problem


Quote:
Expand|Select|Wrap|Line Numbers
  1. DbOperation dbOp = new DbOperation();
  2.         DataSet1 ds = new DataSet1();
  3.         CrystalReport1 rpt = new CrystalReport1();
  4.         DataSet1.ScoreCardTblRow newDr;
Notice how your first three variable assignment actually give a value to the variables? DataSet1 ds "is equal to" a new DataSet(1)

Yet your newDR is not being assigned to anything.
That's what the error means, that it is an unassigned variable, but you are trying to do something with it anyway.

Set it equal to a new datarow before you try to use it as a datarow
Reply