Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# - Add and Update Records
Message
From
11/04/2008 19:57:29
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01309187
Message ID:
01310124
Views:
40
>>>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
Next
Reply
Map
View

Click here to load this message in the networking platform