|
Until you've issued a dataAdapter.Update(), changes won't be "reflected in the DB".
"Data binding" deals with controls and sources of data "in memory" (in your case, the DataSet; in other cases, it might be a different type of object, such as an Entity Model query). To get the data from the "in memory" data source to the "data store" (i.e. the "Database") one needs to issue an Update() sometime; the type of Update being dependent on the data source.
|
|
|
|
|
i used this data adapter instance later on when the user clicks on some button.
the INSERT,SELECT,UPDATE,DELETE commands were set.
then :
dataAdapter.Fill(dataSet, tableName);
textBox.DataBindings.Add("Text", dataSet.Tables[tableName], "someField");
and then later on:
da.Update(dataSet, tableName)
doesn't work...
i read somewhere that this binding is not Bi-Directional.
never mind.. thx guys anyway.
eventually i used the SqlDataReader. simple, easy, and... works!
|
|
|
|
|
hi to all, i was wondering if i can get some help,
i'm srawing on tabs of tab control item that has string and a-16X16 pixel icon of cancel button,
(just like the tabs in a regular browser that have a small button to close the tab).
anyway, i'm tring to make the icon on the selected tab to be red and the other tabs gray.
here is the code:
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
Image img1 = new Bitmap(Application.StartupPath + "\\icons\\cancelGray.png");
Image img2 = new Bitmap(Application.StartupPath + "\\icons\\cancelRed.png");
Rectangle r = e.Bounds;
r = this.tabControl1.GetTabRect(e.Index);
r.Offset(2, 4);
Brush TitleBrush = new SolidBrush(Color.Black);
Font f = new Font("Microsoft Sans Serif", 8.0f);
string title = this.tabControl1.TabPages[e.Index].Text;
e.Graphics.DrawString(title, f, TitleBrush, new PointF(r.X, r.Y));
foreach (TabPage tp in tabControl1.TabPages)
{
if (tp == lastSelected) //LAST SELECTED IS THE THE CURRENT TABPAGE THAT SELECTED.
e.Graphics.DrawImage(img2, new Point(r.X + (this.tabControl1.GetTabRect(e.Index).Width - _imageLocation.X) - 7, _imageLocation.Y));
else e.Graphics.DrawImage(img1, new Point(r.X + (this.tabControl1.GetTabRect(e.Index).Width - _imageLocation.X) - 7, _imageLocation.Y));
}
}
the problem is that the changing colors of the tabs is not correct, i can't figure why when i'm clicking one tab the other is change..
thanks,
modified 31-Dec-20 21:02pm.
|
|
|
|
|
Hi,
in general events may fire more often than you would expect, so it is unwise to use status information from elsewhere when this can be avoided, as such data might be incorrect.
More in particular: why are you using your lastSelected when you have TabControl.TabPages[TabControl.SelectedTab] which is bound to always be the correct current page?
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
what do you suggest instead of the foreach?
and i tried the tabControl1.SelectedTab instead of the lastSelected before, it's only a bad try to fix the problem.
modified 31-Dec-20 21:02pm.
|
|
|
|
|
sagiko wrote: what do you suggest instead of the foreach?
Nothing.
I can't help you any further lacking precise scenarios and symptoms.
sagiko wrote: it's only a bad try to fix the problem
that does not help at all.
To be as vague as you are: fix the problem.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
modified 31-Dec-20 21:02pm.
|
|
|
|
|
Hi all.
I am trying to delete a directory and using
Directory.Delete("some_file_path");
These works just fine if the directory has no files in it but if it has any file, it does not get deleted. What should i do to delete a directory with or without a file?
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
Hi,
write code to delete any files in the directory tree you want to delete. There are basically two ways:
1. ask a list of all files with a GetFiles(path, "*", SearchOptions.AllDirectories), delete all of them, then delete all (now empty) folders and subfolders using Directory.Delete(path, true);
2. write a depth-first recursive method that locates files, deletes them, then deletes the subfolder; this is slightly harder but doesn't get the big memory penalty on huge folders.
NB: since .NET 4.0 there are new methods that relieve the memory consumptions in (1)
PS: there is bound to be a native method that does it all; calling it would require some P/Invoke.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Luc Pattyn wrote: there is bound to be a native method that does it all;
I looked, and was surprised to find that there wasn't one in the Win2K native API. Even then it was still necessary to empty a directory before removing it. I haven't looked at this book (Windows NT/2000 Native API Reference) in a decade, and found it amusing to see ZwCreateMutant and ZwReleaseMutant. I wonder if that was part of Bill's plan to take over the world? It would explain a lot of things about Congress in recent years...
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
I think this will do it.
DirectoryInfo d;
d.Delete(true);
|
|
|
|
|
Which directory will this code delete ?
|
|
|
|
|
There is an overloaded Delete method that takes a boolean parameter 'recursive' to specify that you want the delete operation to be recursive, that is, to delete all subdirectories, files, etc. in the specified path.
This code will do the trick.
Directory.Delete("some_file_path", true);
|
|
|
|
|
Hello,
how can i work with my JS-Objects, which i get over invoking JS in the WebBrowser-Control in my C#-Application? Is there any serializer? I get something like a "DOM-OBJECT" back from JavaScript, but can't work with it. So is there any possibility for example putting the Object into a string/xml-file put this through my invoked script and deserialize that xml-file or string into c#-classes?
Has somebody experience in doing that or working with that objects?
Thanks
|
|
|
|
|
Use the CreateJsonReader and CreateJsonWriter methods of the JsonReaderWriterFactory class to map JSON from / to XML.
|
|
|
|
|
Hello,
and how to use it? Because when i doing HtmlDocument.InovkeScript(...) i get as a return value a "object"... and if i try out which type it is i get "DOM-Object" or "COM-Object" (i'm not sure now), so how do i use this object which i get back in this JsonReader? Because in tutorials for this JsonReaderWriterFactory everyone uses some XmlDocuments...
Thanks
|
|
|
|
|
JSON objects consist of "name / value" pair elements.
The System.Xml.XmlDictionaryReader (and not "XmlDocuments") that you get back from the Factory consists of "name / value" pairs.
You use the Factory to read the JSON object as a "stream" and get back a XML reader which you then read using the .Read() method. Each "read" will get you a node with a Name, Value, NodeType, etc. Sometimes the Value contains nothing and you need to use one of the "Node.Readxxx" methods (e.g. ReadString()).
If you don't know what's in the JSON object, you're first go-around would be to simply dump everything for each node.
|
|
|
|
|
I am working with an application that has a background worker thread.
Passing infroamtion back is easy by using ReportProgress .
I can cancel the thread but is there a simple way to make calls to it to pass data? I have looked at message queues but it looks like overkill.
Recommendations?
Thanks.
[Update] System.Collections.Queue will do what I need plus it has a Synchronize method for thread safety.
modified on Friday, November 27, 2009 7:01 PM
|
|
|
|
|
yetch - if a noob had asked this question I'd have said - 'needs more design' - I think your options are a shared & thread-safe queue or similar or message queues Elaine - while it may 'look like overkill' when you're dealing with threads etc, its the tendency to cut-corners that brings people undone with locking etc
just my 0.02c worth
'g'
|
|
|
|
|
Trollslayer wrote: Passing infroamtion back is easy by using ReportProgress
That's correct for GUI output, for anything else communication with another thread needs one of many things (shared objects with locks, messages, queues, etc), the best pick very much depends on what kind of app it is, what kind of threading effects you have in mind. So if you want specific advice, tell us a lot more!
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
OK, fair comment
The project is for running script based tests on embedded systems which will have a GUI for control and logging, the script engine itself and optional lower layers for communications.
Communication between layers will be low bandwidth since msot of the time the system will be waiting for response from the target system.
Also, I will need the option to run multiple instances.
The test scripts will be a plain text form so testers won't have to worry about programming and doing a load of damage.
Does that help?
Elaine
|
|
|
|
|
Hi Elaine,
no the situation isn't clear yet. I have no idea how long a test job lasts, and whether you want to change parameters in the middle of a test, etc.
I'll try to provide a general answer:
1. if jobs (units of work that will be executed sequentially) don't need parameter changes while running, either use a new BGW for each job, or create a queue (with a lock) where the main thread produces jobs and the BGW executes (i.e. consumes) jobs. With a queue, the BGW would have a main loop which dequeues a job and blocks when none available.
BTW: a queue can be implemented in many ways, e.g. by using the System.Collections.Queue class, the System.Collections.Generic.Queue<T> class, or something you build yourself probably on top of a List<T>
suggestion: carefully read the MSDN remarks on the queue you choose (thread safety!).
2. if a running job needs a simple parameter change, just change it (assuming no synchronization is necessary, i.e. the parameter is allowed to change at all times). If the parameter cannot be read in one CPU instruction, or if it should not be changed at random times, or if there are several parameters that need to be consistent, I would probably recommend an extra class:
2a. as a minimum a little Parameters class, so the producer can create a new instance, insert the new set of values, then have the consumer update its Parameters reference in a cooperative way (e.g. at the top of its execution loop).
2b. a more structured approach would take a Job class that hides the BGW, and provides properties for all parameters, so it also can hide your consistency stuff.
Example in pseudo-code (not quite safe):
class Job {
Parms initialParms;
Parms runningParms;
Job(Parms parms) {
initialParms=parms;
}
Run() {
runningParms=initialParms;
runPart1();
runningParms=initialParms;
runPart2();
runningParms=initialParms;
runPart3();
}
ParmType1 Parm1 {set {initialParms.Parm1=value;}}
ParmType2 Parm2 {set {initialParms.Parm2=value;}}
}
struct Parms {
ParmType1 Parm1;
ParmType2 Parm2;
}
The example isn't safe: you could be modifying Parm1 while the BGW is executing runningParms=initialParms; resulting in inconsistencies. So you need to provide some safety measure. A possible way would be:
class Job {
ManualResetEvent MREproducer;
ManualResetEvent MREconsumer;
Parms initialParms;
Parms runningParms;
Job(Parms parms) {
initialParms=parms;
MREproducer=new ManualResetEvent(true);
MREconsumer=new ManualResetEvent(false);
}
Run() {
updateParms();
runPart1();
updateParms();
runPart2();
updateParms();
runPart3();
}
updateParms() {
MREproducer.WaitOne();
runningParms=initialParms;
}
ParmType1 Parm1 {set {MREconsumer.WaitOne(); initialParms.Parm1=value;}}
ParmType2 Parm2 {set {MREconsumer.WaitOne(); initialParms.Parm2=value;}}
BeginParmChanges() { Clear(MREproducer); Set(MREconsumer);}
EndParmChanges() { Clear(MREconsumer); Set(MREproducer);}
}
struct Parms {
ParmType1 Parm1;
ParmType2 Parm2;
}
remark: to hide the BGW inside Job, create it in the constructor, and turn Run() into a DoWork() handler.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Thanks Luc.
I won't be changing parameters 'on the fly' but will need to stop, pause and continue.
It may be necassary in the future to inject a script when the main script is paused.
System.Collections.Queue looks a good candidate and has a Synchronized method for thread safety.
Elaine
|
|
|
|
|
|
Thanks Daniel.
My application is simple enough I can use the first soluttion in this case (I hope!).
I have bookmarked both of these and now have a separate favourites folder called "Threading".
|
|
|
|