|
Hi, I have two datatables each table contain one column. I want to make a new data table that should contain both columns. Can u plz tell me how can I do this in c#.net. I will be thankful to you,
Regards,
|
|
|
|
|
dt2.Columns.Add ( dt1.Columns [ 0 ].ColumnName , dt1.Columns [ 0 ].DataType ) ;
Will create a column with the same name and type, but you'll have to iterate the rows to copy the data.
|
|
|
|
|
thanks a lot for ur reply, plz tell me is there any way to copy the data without iteration. actually i want to copy the whole column in another datatable.
thanks,
|
|
|
|
|
When I run a method using the BackgroundWorker in a class do I have to pass any arguments to that method using the Argument property of DoWorkEventArgs or can I just access properties and variables defined within the class?
|
|
|
|
|
If they're startup arguments then it's safer to pass them through the DoWorkEventArgs object. If you're accessing properties of the form you'll have to be careful how you access them because of concurrency / threading issues.
|
|
|
|
|
They aren't GUI properties, just some user defined properties to return a value.
Why is it safer to pass startup arguments through the DoWorkEventArgs?
Every example I have seen seems to assume that the entire background process can be achieved in one function without recourse to other properties, methods and variablies of the class.
|
|
|
|
|
RugbyLeague wrote: Why is it safer to pass startup arguments through the DoWorkEventArgs?
Probably because the arguments (especially value types) might change by the time DoWork runs. Like Ed said, if you are going to access members, you'll have to make sure that you are using proper synchronization.
|
|
|
|
|
They won't change, there's nothing to change them, so can I just access them as usual?
|
|
|
|
|
|
Thanks
|
|
|
|
|
Not quite, you're probably going to get a ThreadAccessException if you do that. You'll need to create a delegate which can return the value. You can then pass this delegate to the Control.Invoke method to retrieve the value. Alternatively you can use the feature of anonymous delegates (can't remember what it's called) where you can access the variables surrounding it. E.g. (note I'm writing this code from memory)
internal delaget int GetCurrentCount();
private int count = 100;
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
int threadedCount = -1;
this.Invoke(new GetCurrentCount(delegate() { threadedCount = this.count; }));
}
|
|
|
|
|
hi i want to listen on http port, or i want to make a socket server that will listen on http port and get the data, but when i use socket bind method then this exception is raised
"Only one usage of each socket address (protocol/network address/port) is normally permitted"
can u plz help me how to do that i mean get the data from http port using sockets.
Regards.
Tasleem Arif
|
|
|
|
|
You can only listen to 1 port at a time. That mean, http port is being used, another application listen also in this port. You must shutdown this application so you can start your application.
|
|
|
|
|
hi
is that anyWay that i see preview of setup dialogs in setup project, (i want to change banners of setup dialogs, but i don't what is resolution, and how to see preview of it ?)
thanks
|
|
|
|
|
|
why not just build it and run it? If the rest of the installer takes to long for this to be feasible then how about making a dummy setup project that just runs through your dialog sequence and exists?
|
|
|
|
|
How to display a message while draging and droping an item from the tree view?
plz help
thanks
Aparna.B
|
|
|
|
|
Take a look at the DragDrop event. Handle the event, and put your code inside it.
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
it is not working in drag and drop event
|
|
|
|
|
What do you mean it's not working? Be more specific, "it's not working" could mean quite a few things. There is an error on build, you get an exception when running, or it doesn't do anything. If it just doesn't do anything, you might want to try DragEnter , DragLeave , or DragOver events. Maybe those better suit your needs.
I'm going to become rich when I create a device that allows me to punch people in the face over the internet.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
|
|
|
|
|
Hi,
I am using the following code to write to a .csv file.
Each time this is run, a new file is created, but the old one gets deleted.
I would like to add a new file each time so the files get added to the files folder.
I have tried FileMode.Append, FileMode.Append but none of them do what I am after
Thanks
private const string dir = @"C:\Files\";
private const string path = dir + "Securities.csv";
// create the output stream for a text file
StreamWriter textOut =
new StreamWriter(
new FileStreampath, FileMode.Create, FileAccess.Write));
|
|
|
|
|
Do you want to have a new file every time? Use a different file name every time, such as appending a time stamp to the file name. You are overwriting the same file every time right now.
|
|
|
|
|
I see.
Now trying to change the name each time by adding the time to the path as follows.
What is the correct syntax for the following code please?
Is this correct?
Thanks
private const string path = dir + "Securities_" + DateTime.Now.ToString() + ".csv";
|
|
|
|
|
DateTime.Now.ToString() will have invalid characters (semicolon etc)for a file name so you do not want to use ToString().
private const string path = dir + "Securities_" + DateTime.Now.ToString("HHmmss") + ".csv";
You _may_ still be overwriting older file with the same file name of same time stamp, though, but you can add date to the file name, ie DateTime.Now.ToString("yyyyMMddHHmmss"), assuming you wont be creating more than 1 file within 1 second.
DateTimeFormat[^]
modified on Wednesday, January 23, 2008 7:45:42 AM
|
|
|
|
|