|
Hai all,
I have two data table.dt1,dt2. From dt1 i need to insert some of records into dt2.
for that i am doing like this.
foreach (datarow dr in dt1.rows)
{
here i am adding record into dt2.after adding i am removing tat row from first dt1.
}
so again when it comes to foreach loop its throwing error like this.Collection was modified; enumeration operation might not execute.
can anyone tell me how to rectify this error.
thanks in advance
Lijo
|
|
|
|
|
Use a for loop instead, but even then I'm not sure.
You can't just add a DataRow to a DataTable, and I'm not sure about removing either; .Delete doesn't remove the DataRow.
You'd need to show the code.
|
|
|
|
|
You can't modify a collection within an enumeration block.
Using foreach, you will not be able to achieve this. Instead, you need to use While loop.
Best Regards,
Sam Xavier
www.componentone.com
|
|
|
|
|
Hi all,
I am a newbie of .NET c# programming.
I just take over a Data Recording System which use Visual Studio. NET 2002 (C#) to built a PC-based application, and use Ms Access 2000 as database.
I need to enhance a existing Windows Form that add more fields for user to input.
First of all, I add one textbox for testing, it works fine to save and retrieve.
and then I add the second textbox.... it's OK.
But when I add the third one. Error occurs.
When I click the SAVE button. It prompt a error message that "Expression too complex". So that I cannot save and add more input field to this Windows Form.
Do you have any idea and solution of this error.
I really need your help. Thanks.
The application is using OleDbCommandBuilder, DataAdapter.Update() for update, insert, etc.
|
|
|
|
|
I think we need to see the code to understand the error. Are you using nasty controls that auto generate SQL ? I suspect you are, and that the auto generation is failing. Try writing your own SQL.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Smells like SQL injection
|
|
|
|
|
|
PIEBALDconsult wrote: Linq?
Huh?
|
|
|
|
|
(Linq generates SQL, yes?)
|
|
|
|
|
Still not following how you get to LINQ
|
|
|
|
|
Hi all, thx for your reply.
The system use DataAdapter.Update() to update dataset
When user click SAVE button, it would run the following function.
AppFacade.SaveApp(dbConnectionString, dsAppData);
And SaveApp function as follows:
public void SaveApp(String dbConnectionString, DataSet dsData)
{
DBExecute dbexe = new DBEngine.DBExecute();
DataTable dtApp = dsData.Tables[AppData.SYS_TABLE_NAME];
DataTable dtLoc = dsData.Tables[AppDetailData.SYS_PROJ_LOCATION_TABLE];
......
......
try
{
dbexe.dbConnectionString = dbConnectionString;
dbexe.TransactionInitial();
dbexe.UpdateDataTable(dtApp);
dbexe.UpdateDataTable(dtExtApp);
......
......
dbexe.TransactionComplete();
}
catch (Exception e)
{
dbexe.TransactionRollBack();
throw e;
}
finally
{
dbexe = null;
dtApp = null;
dtExtApp = null;
......
......
}
}
// Public functions to update a datatable
public int UpdateDataTable(DataTable dt)
{
this.BuildCommands(dt.TableName);
if (dt.GetChanges() != null)
{
int intRtn = pAdapter.Update(dt.GetChanges());
return intRtn;
}
else
return 0;
}
public int UpdateDataTable(DataSet ds, string tableName)
{
this.BuildCommands(tableName);
if (ds.Tables[tableName].GetChanges() != null)
return pAdapter.Update(ds.GetChanges(), tableName);
else
return 0;
}
....
....
/// Public functions to build SQL command and parameters
private void BuildCommands(string tableName)
{
string strCommand = "SELECT * FROM " + tableName;
OleDbCommand comm = new OleDbCommand(strCommand, pConnection);
comm.CommandType = CommandType.Text;
comm.Transaction = myTrans;
pAdapter.SelectCommand = comm;
OleDbCommandBuilder cb = new OleDbCommandBuilder(pAdapter);
pAdapter.InsertCommand = cb.GetInsertCommand();
pAdapter.UpdateCommand = cb.GetUpdateCommand();
pAdapter.DeleteCommand = cb.GetDeleteCommand();
pAdapter.SelectCommand.Transaction = myTrans;
pAdapter.InsertCommand.Transaction = myTrans;
pAdapter.UpdateCommand.Transaction = myTrans;
pAdapter.DeleteCommand.Transaction = myTrans;
}
|
|
|
|
|
DataAdapter.Update can only work on very simple things; I suggest you avoid it.
|
|
|
|
|
HI
I want Output in gridview as
Site1 Site2 Siten Total
Pt1 5 0 10 15
Pt2 2 1 3 6
Pt3 1 2 1 4
Pt4 2 1 0 3
In above gridview Site1,site2,site3 and Pt1,pt2,Pt3,Pt4 these all shoul come dynamcally and count should also come dynamcally count like-5,10,15.
Please let me no code for this in C#
thnx
GroCareer
Waiting for replay
|
|
|
|
|
GroCareer wrote: In above gridview Site1,site2,site3 and Pt1,pt2,Pt3,Pt4 these all shoul come dynamcally and count should also come dynamcally count like-5,10,15.
Come from where?
GroCareer wrote: Please let me no code for this in C#
Why? try for yourself and post your code if it doesn't work, then someone will help.
Next you'll be saying its urgent - probably because youi need to habd your homework in.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hello everyone,
I am migrating from C++ to C#. And I am debugging a multi-threaded program and I need to print out the thread ID. In C++, I am using GetCurrentThreadID method, but in C#, I only find Thread.CurrentThread.ManagedThreadId.
My questions are,
1.
Does Thread.CurrentThread.ManagedThreadId have the same effect and can serve my purpose?
2.
I am confused about what means "ManagedThreadId", does there is some peer called "NonManagedThreadId"?
thanks in advance,
George
|
|
|
|
|
Hi George,
1. no
2. no
there is no link between managed threads and kernel threads.
managed threads are logical things, kernel threads are physical things.
even if it seems there is a one-to-one correspondence, .NET does not promise that;
in fact they claim multiple managed threads could be executed by a smaller number of
kernel thread.
As a consequence, there is simply NO WAY to identify your threads; not by name (Windows
does not know about thread names), and not easily by thread IDs, they are confusing
at the least.
What you can do is catch the managed thread ID when the thread gets created,
attach a thread name to it (using a Hashtable/Dictionary), then keep track of your
threads by asking them their ID, and look up the thread name you assigned earlier.
But that is a rather clumsy workaround for a lernel shortcoming.
|
|
|
|
|
Thanks Luc,
1.
My application is pure C# application, and I want to dump thread ID to detect the behavior of each thread, so that I can find deadlock/re-entrance/how many times a thread enters a specific method, something like this.
After reading document, I am confused whether I can use ManagedThreadId property, my concern is for example, whether two threads will map to the same ManagedThreadId, so that the monitor is not accurate to serve my purpose.
2.
Luc Pattyn wrote: As a consequence, there is simply NO WAY to identify your threads; not by name (Windows
does not know about thread names), and not easily by thread IDs, they are confusing
at the least.
Why not can not be identified by ManagedThreadId? Could you show me a scenario please?
3.
Luc Pattyn wrote: What you can do is catch the managed thread ID when the thread gets created,
attach a thread name to it (using a Hashtable/Dictionary), then keep track of your
threads by asking them their ID, and look up the thread name you assigned earlier.
But that is a rather clumsy workaround for a lernel shortcoming.
I am confused why ManagedThreadId is not enough? Could you show me a scneario when just using ManagedThreadId is not enough please?
regards,
George
|
|
|
|
|
|
|
ryrt ruyeuttruuer e re njsdrfg irire ergtri tegr regtrre reirtirtgiers rtretrtgre
|
|
|
|
|
Can you speak English please?
regards,
George
|
|
|
|
|
Hi George,
ManagedThreadId is fine for identifying threads within .NET with two remarks:
1. it is a number, not a name; important stuff should be identified by name.
2. it does not map easily to the thread IDs as can be seen from other tools, such as
Task Manager, SystemInfo, etc.
|
|
|
|
|
Thanks Luc,
1.
Luc Pattyn wrote: 2. it does not map easily to the thread IDs as can be seen from other tools, such as
Task Manager, SystemInfo, etc.
Because Task Manager will use a different ID? And ManagedThreadId is just CLR internal thread ID?
2.
What do you mean this before?
--------------------
As a consequence, there is simply NO WAY to identify your threads; not by name (Windows
does not know about thread names), and not easily by thread IDs, they are confusing
at the least.
--------------------
Why no way? I think you mentioned in last post ManagedThreadId is ok to identify -- "ManagedThreadId is fine for identifying threads within .NET"?
regards,
George
|
|
|
|
|
Hi George,
I found no easy way to relate ManagedThreadID inside a .NET app to the Thread IDs listed
by kernel-level tools such as Task Manager, SystemInfo, etc. That makes it hard to
observe multi-threading behavior unless you build a lot of code into the app itself.
|
|
|
|
|
Thanks Luc,
--------------------
As a consequence, there is simply NO WAY to identify your threads; not by name (Windows
does not know about thread names), and not easily by thread IDs, they are confusing
at the least.
What you can do is catch the managed thread ID when the thread gets created,
attach a thread name to it (using a Hashtable/Dictionary), then keep track of your
threads by asking them their ID, and look up the thread name you assigned earlier.
But that is a rather clumsy workaround for a lernel shortcoming.
--------------------
So, you think the same is the same in TaskManager and in the .Net App -- even if the ID are not the same? And you use name to link the relationship between them?
regards,
George
|
|
|
|
|