473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.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
Oct 31 '09 #1

✓ answered by tlhintoq

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

1 1731
tlhintoq
3,525 Expert 2GB
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
Oct 31 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: | last post by:
We have an object factory that returns weakly typed datasets (just plain ol' DataSet's). I need to cast it, or transform it, or map it to a strongly typed dataset. There's an old adage I heard...
2
by: theWizK | last post by:
Hello all. I have noticed that when I generate a strongly-typed dataset from an xml schema that the DataTables that are generated have their constructors marked as internal. What this means is...
1
by: Job Lot | last post by:
I am confused how strongly typed dataset is different from un-typed dataset. Is there any good link explaining pros and cons of both? Which one should be used preferably?
3
by: Duncan Welch | last post by:
I have a strongly typed dataset that returns two tables - "items" and "itemdetails". In the strongly-typed dataset designer, I've created a link (relationship) between the two tables based on a...
0
by: Uchiha Jax | last post by:
When using a strongly typed dataset (generated from the Visual Studio IDE from an XSD file) and databinding I get a really odd error when binding to both a combox and a datetimepicker. I bind...
2
by: David | last post by:
I have been developing applications with Java for quite a while but I am new to .NET development. I am trying to learn the ".NET way" of creating Strongly Typed Objects from a database. The...
1
by: HardBap | last post by:
I've created a strongly typed DataSet (Customers.xsd) using the xsd.exe tool. I want to be able to access fields using ds.Customer.CompanyName. The problem is when I return this DataSet from a...
1
by: PeterH | last post by:
I am developing a web service in VB.Net that returns data from a server. I have an .asmx page that uses a strongly typed dataset and I would like to return data in the form of strongly typed data...
2
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
When I'm debugging a Windows Forms Application in VS2005 IDE, how can I check whether a dataset is strongly typed or not in Watch window? Are there some properties or methods only exist for...
4
by: Rachana | last post by:
Hi, I have understood Data Sets but what is meant by typed/untyped/ strongly typed datasets. Can any one explain me or suggest any site/ article, to get these concepts (and their ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.