Strongly typed dataset problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dragon52
    New Member
    • Jun 2009
    • 72

    #1

    Strongly typed dataset problem

    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.ScoreC ardTblRow newDr;
    newDr.Community Name = dr["Community"].ToString();

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

    Anyone know what I should do?

    Here is the complete code

    Code:
            DbOperation dbOp = new DbOperation();
            DataSet1 ds = new DataSet1();
            CrystalReport1 rpt = new CrystalReport1();
            DataSet1.ScoreCardTblRow newDr;
    
            protected void Page_Load(object sender, EventArgs e)
            {
                DataTable dt;
                string sql = "SELECT * FROM ScoreCard";
    
                dt = dbOp.GetDataSet(sql).Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    [B]newDr = ds.ScoreCardTbl.NewRow();[/B]
                    newDr.CommunityName = dr["Community"].ToString();
                    rpt.Rows.Add(newDr);
                }
    
            }
    Denis
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Code:
    DbOperation dbOp = new DbOperation();
            DataSet1 ds = new DataSet1();
            CrystalReport1 rpt = new CrystalReport1();
            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

    Comment

    Working...