|
I've knocked up a quick test with a dataset containing 2 table with one column: AColumn.
It doesn't appear to have the problem you observer.
Is there perhaps a recursion problem within your employee code?
Just a thought.
I also have used similar code elsewhere with no problems.
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text += "1: Running with no entries\r\n";
DataSet1 ds = new DataSet1();
LoadFromDataSet(ds);
textBox1.Text += "Finished 1\r\n";
textBox1.Text += "2: Running with entries\r\n";
DataSet1.DataTable1DataTable dtbl =
new DataSet1.DataTable1DataTable();
ds.DataTable1.AddDataTable1Row("A record 1");
ds.DataTable1.AddDataTable1Row("A record 2");
LoadFromDataSet(ds);
textBox1.Text += "Finished 2\r\n";
}
public bool LoadFromDataSet(DataSet ds)
{
bool bSuccess = false;
if (ds != null)
{
foreach (DataTable table in ds.Tables)
{
foreach (DataRow row in table.Rows)
{
textBox1.Text += "In Rows: data: " +
((DataSet1.DataTable1Row)row).AColumn + "\r\n";
}
}
bSuccess = true;
}
return bSuccess;
}
The above code works fine.
Regards
ChrisB.
|
|
|
|
|
No recursion at all. It goes into that function and starts an endless loop in the innermost foreach. According to everything I know about foreach loops, it certainly shouldn't do what I'm seeing it do. If I change it to a plain for loop, it works fine.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I'm sure you've tried it already, but have you commented out the code in the innermost foreach to see if it does the same thing?
Good luck - I hate that kind of debugging!
|
|
|
|
|
John Simmons / outlaw programmer wrote: plain for loop, it works fine.
Ok, I've had a bit of a think about it.
The for loop knows in advance how many rows / tables there are, and when it hits that limit it stops.
The foreach will keep going until it gets to the end. If your code adds a row / table to the dataset, then the foreach will then check that row / table (resulting in another execution of the inner code and another row / table being added (although I know you said there was no recursion, but that seems like the most likely scenario from the data I have available).
Why not do an overloaded version of that method that accepts a datatable rather than a dataset? then you only need to loop through the datarows in that table and load an employee for each.
ChrisB.
|
|
|
|
|
What are the actual contents of what's its looping over?
Is it repeating the 0th record? Is looping over all records multiple times? Mockup a simple test case and step through it. Is there any threading involved that might be modifying the records?
Database experts, is it possible to create circular datasets?
Todd Smith
|
|
|
|
|
things that might be worth trying:
1 Check in the debugger what the value of row actually is
2 your if checks for the number of tables in the ds but actually there could be tables that contain no rows
3 make sure that LoadFromDataRow() does not change its argument.
4 let us know when you find it
_____________________________________
Action without thought is not action
Action without emotion is not life
|
|
|
|
|
WAG: Maybe you've deleted rows from the DataSet, but you haven't yet called AcceptChanges()[^].
|
|
|
|
|
Nope. The dataset is created in the calling function and it's contents are whatever is returned by a stored procedure. The stored proc posts an out parameter that indicates normal/abnormal exit, and after that out parameter is verified), the dataset is immediately passed directly to the function in question.
Nice try, though.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi,
I am trying to use a particular dll bought from a company that has a strong name. As a consequence had to give a strong name to all the dlls involved in the project. Among the external Dlls that I'm using are the following microsoft application block dlls:
Microsoft.Practices.EnterpriseLibrary.Caching.dll
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Configuration.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Logging.dll
so I had them strong named using mycompany.snk key as well which went successful. And once I referenced them properly in the project it compiled without any problems. So far so good.
However when I access the Cache Factory while loading the application I get the following error:
------------------------------------------------------------------------------------------------------------
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in microsoft.practices.enterpriselibrary.configuration.dll
Additional information: File or assembly name Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, or one of its dependencies, was not found.
------------------------------------------------------------------------------------------------------------
Any ideas why this is happening and how may I go around it, have been stuck with this issues since ages....
Regards,
Fahd
|
|
|
|
|
Hi,
AFAIK an exe or dll can only obtain a strong name if all other dlls it needs also have
strong names; as a result you buying a strong-named dll should not force you to do
anything, it must be perfectly possible to use it in a non-strong-named environment.
The rationale is: strong naming exists to protect an app; a protected app must be
unwilling to rely on a dll that may have been tampered with, hence it requires its
referenced dlls to be strong named, but not the other way around.
Hope this helps.
Luc Pattyn
|
|
|
|
|
thanks Luc
well its being referred to in an assembly and therefore i need to strong name it as well.
any how i managed to get the issure resolved it was a bad entry in one of the config files that referred to unsigned version...
thanks though
fahd
|
|
|
|
|
I have created an assembly and added reference to this dll in my web project I have also used USING statement on my web form...However the Intellisense doesnt work with the classes in this assembly...
I am however able to instantiate and use classes from this assembly without errors..
Any ideas in getting intellisense to work with this assembly..
Thanks
Joel
JO
|
|
|
|
|
Hi,
the Intellisense info is collected in a separate xml file, provided you enable this
feature (by specifying the file name) in the project's properties.
It remains available as long as you keep the xml file next to the dll file itself;
referencing the dll file in another project makes Visual look for the xml file in
the same directory.
Luc Pattyn
|
|
|
|
|
Luc,,
Thanks for your input...I dont wanna document or specify additional information for my classes.I just want the constructor name and signature to show up when I an using object of this class..
As in
MyClass tstClass=new (I want MyClass name and the overloads for the constructor to automatically appear here)
Thanks
Joel
JO
|
|
|
|
|
Hi Joel,
Member names are available to Intellisense as soon as you have provided these two:
- a reference to the dll file (Add Reference... in Solution Pane's context menu)
- a using statement (at the top of your C# source files).
Warning: you see method names only if:
- you have a class instance name for non-static methods; e.g. FileInfo f; f.Open();
- you have a class name for static methods; e.g. File.Open()
The extra info you can add with triple slashes goes into an xml file, cfr my previous message.
Luc Pattyn
|
|
|
|
|
I have an aplication with a media player control . Im trying to get it to load the last played file when the application is run again . ive allready used the code below to set the path to the last file the media player played .
// Set last url
Microsoft.Win32.RegistryKey key;
key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\\Flexbeta\\VideoDesktop");
key.SetValue("LastFile", SelectFile.FileName);
key.Close();
The problem is when i try to use the int value LastRun to control the media player control i get the folowing build exception "Cannot implicitly convert type 'int' to 'string'" because MediaPlayer.URL requires a string value . Im looking for a way to use the int value LastRun as the media player URL
//Load the last file
Microsoft.Win32.RegistryKey key2;
key2 = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\\Flexbeta\\VideoDesktop");
key2.GetValue("LastFile");
int LastRun = (int)key.GetValue("LastFile");
MediaPlayer.URL = LastRun; <-- problem !!!
Any ideas ?
|
|
|
|
|
Use static methods of int class. int.Parse or int.TryParse
|
|
|
|
|
\Can you give an example ive never tried this before
|
|
|
|
|
int iTmp = int.Parse("8");
|
|
|
|
|
Why on earth are you trying to use an integer as a file name in the first place?
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi,
I expect the line
key.SetValue("LastFile", SelectFile.FileName);
stored the file name as a string.
And I expect MediaPlayer.URL needs a file name, hence a string too.
So I dont understand why you want to use an int LastRun ?
I would try
string LastRun = key.GetValue("LastFile");
MediaPlayer.URL = LastRun;
Luc Pattyn
|
|
|
|
|
I am using windows xp as my OS. set the system time format as US format. I have developed an application in c# with msssql server as back end. When i change my system date format as UK format (dd/mm/yyy) i am getting the application crashed. The error is comming in the sql query to insert into db. It shows the date is overflow.
Can anyone figure out the issue
regards
hari
aspspider.net/rkharikrishnan
|
|
|
|
|
Are you storing the date in a neutral format such as UTC?
only two letters away from being an asset
|
|
|
|
|
Yep, date formats are a popular reason for failure.
What is 01/02/03 supposed to mean if you are not sure which date format is used ?
And which of 28/02/03 and 01/31/03 does not exist (and will cause a Parse exception) ?
So best is to use a universal format (such as UTC), independent of what will be
input/output to the users.
Luc Pattyn
|
|
|
|
|
thanks for teh reply.
can you tell me how i can use UTC format. I am having datetime pickers in my form and also i have to use current date
|
|
|
|