Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# - Add and Update Records
Message
From
13/04/2008 17:30:32
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01309187
Message ID:
01310305
Views:
39
>Tim & Bonnie:
>
>I am sure that I'm totally lost here, and I'm not sure that I'm communicating the problem clearly.
>
>I created a simple project with a Test DB and a Customers table and called the project Typed_DS_Example.
>There is a simple Typed Dataset called DSCustomers in the project. The code loads it from the SQL Customers table. The project is here:
>http://www.geocities.com/kevin.marois/typed_ds/typed_ds_example.zip
>The DB is in the Data folder.
>
>
>Please see these 2 pics:
>
>In the first, you can see that there is an object in the Visualizer called 'DSCustomers'. The structure
>is correct, but there is no data.
>http://www.geocities.com/kevin.marois/typed_ds/visualizer1.jpg
>
>
>In the second, you can see that there is another object in the Visualizer called 'Customers'. The structure is correct, and there is data.
>http://www.geocities.com/kevin.marois/typed_ds/visualizer2.jpg
>
>Now I don't know if this is what is supposed to be happening. I have no experience at all using a
>typed dataset. If this is not correct, then can you show me what's wrong? If it IS correct, the how
>do I use this dataset to Add, Edit and Delete a customer?
>
>Signed, Frustrated In California :)
>
>

I have not used the visualizer you are showing and honestly it is a little hard for me to see in your pictures.
Since you are at a breakpoint, you should be able to drill down through the object to see the hierarchy.

Dataset is a container to hold tables. It isn't a table itself.
In the dataset you should have a table. So try adding this to your code after your breakpoint and after the data is supposed to be filled and inspect the myTable variable with each loop through to see what you get. Maybe there is only one table which is what you are expecting.
foreach(DataTable table in dsCustomers.Tables)
{
   string myTable = table.TableName;
}
Tim
>
>
>
>>>>>Ok, I made some progress, but now I have a question.
>>>>>
>>>>>I created a Typed DataSet and I wrote a simple data access class which returns an instance of the
>>>>>data set.
>>>>>
>>>>>When I look at it in the DataSet Visualizer I see 2 tables - the Typed Dataset and the underlying table.
>>>>>The DataSet has no data, but the table does. I'm not sure this is right, and I surely don't understand
>>>>>it.
>>>>>
>>>>>Can you provide some insight?
>>>>>
>>>>
>>>>I can tell you what I do. I create a typed Data set TruckDataSet for instance but the table name I created inside there is "Trucks" which matches the table name I am going to fill it with. All the fields I create in there are also a match for type and name as the actual columns in the table.
>>>>
>>>>I put an instance on the form where I need to use the data. My DataAccess Layer in this older app has a general routine where I fill the dataSet passed into it.
>>>>
>>>>So When I call it this way:
>>>>DataAccess data = DataAccess.Instance; // I am using a singleton pattern
>>>>
>>>>data.GetAllTrucks(dsTrucks);
>>>>
>>>>The dsTrucks is the name of the dataset I dropped on the form. This way I am passing in the actual dataset I need filled to the data access layer.
>>>>
>>>>Now, I wouldn't do it this way necessarily now because I also have a business layer in the middle. But I think Kevin probably what you are seeing is possibly an issue with the names of the table you added to the DataSet. It needs to match your actual table I think as do the columns.
>>>>
>>>>Try that and see if that is what you see. The layers you will see are a DataSet, a DataTable in there, Rows in the table, and each row will have columns.
>>>>
>>>>See if any of that helps you out.
>>>>Tim
>>>
>>>
>>>I don't understand this, but I did change the table name to match the SQL table. The column names match and I still get the same results.
>>
>>If you only see one table in the DataSet at design time then something in your code must be creating the additional table. Check through your code and see if you are filling the DataSet and using a different table name somewhere.
>>Best I can say right now.
>>
>>Here is a little code for what I am doing with the above example. Keep in mind this isn't quite the way I would do it again, but an example of what does work.
>>
>>
>>// Fills the dataset for Trucks when dataset for trucks is passed in.
>>public void GetTrucks(TrucksDataSet dsToFill)
>>{
>>	try
>>	{
>>		string select = "SELECT * FROM Trucks";
>>
>>		this.FillDataSet(this.oledaTrucks, dsToFill, select);
>>	}
>>	catch (Exception ex)
>>	{
>>		EventLogger.LogException(ex);
>>	}
>>}
>>
>>// Fills the dataset
>>public bool FillDataSet(OleDbDataAdapter da, DataSet dsToFill, string select)
>>{
>>	bool dataSetFilled = false;
>>	int numRows = 0;
>>	try
>>	{
>>		if(dsToFill != null)
>>		{
>>			Debug.WriteLine(select);
>>
>>			//fill the DataSet
>>			dsToFill.Clear();
>>			da.SelectCommand = MakeOleDbCommand(select);					
>>			numRows = da.Fill(dsToFill);
>>			dataSetFilled = true;
>>
>>			Debug.WriteLine(" (" + numRows + " rows returned)");
>>		}
>>	}
>>	catch(Exception ex)
>>	{
>>		EventLogger.LogEvent(select + " (returned " + numRows + " rows)", "FillDataSet");
>>		EventLogger.LogException(ex);
>>	}
>>
>>	return dataSetFilled;
>>}
>>
>>
>>
>>I hope it helps
>>Tim
Timothy Bryan
Previous
Reply
Map
View

Click here to load this message in the networking platform