|
Once again, the following lines will not do what you think they will:
adapterProducts.InsertCommand.Transaction = connection.BeginTransaction();
adapterProducts.Update(dS.GetChanges(), "products");
adapterProducts.InsertCommand.Transaction.Commit(); If you read the documentation for OleDbTransaction you'll see that a connection must be open for the transaction to be effective, and as I told you before (and the documentation for DataAdapter.Update also states) the DataAdapter opens and closes the connection itself. Not only are you wasting CPU cycles on useless instructions, but you'll get a false sense of security that your update is transacted.
Besides, when using a transaction you need to add a call to Rollback in the catch block to be effective.
If you want to try this, open and close the connection yourself. The default implementation of DbDataAdapter (which extends DataAdapter and from which OleDbDataAdapter directly derives) will not re-open the connection, and it will not close the connection if it didn't opened it in the first place. Create a new OleDbTransaction and associate it with your OleDbCommand s (read the documentation for OleDbTransaction because you're not using it correctly anyway). After Update complete commit it (Commit ). In the catch block roll it back (Rollback ).
After using the designer (VS.NET) to generate the commands for an OleDbDataAdapter (which I believe I recommended to you before - writing examples is always helpful) it's apparent that OLE DB does not support combined SQL expressions. Why? Probably because OLE DB is a generic API for accessing data via providers and to assume that a provider supports combined expressions would be faulty. What you'll need to do, instead, is to call DataAdapter.Fill to re-update the DataSet and/or contained DataTable s (depending on how you call Fill .
To note, the SqlCommand does support combined expressions and, if you have a choice, would be better of using SQL Server 2000 or the "free" Microsoft Data Engine (MSDE) if you have a qualifying product - Visual Studio .NET being one of them (this gives you redistribution rights as well, but be sure to read the EULA). MSDE is SQL Server 2000 but supports limited connections (20, IIRC). This gives you access to stored procedures, transaction support, replication, and so much more.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Does anyone know how to add text to a TextBox programaticaly without the cursor jumping to the beginning of the text?
Thanks.
avivhal
|
|
|
|
|
If you take a look at the documentation for the TextBox control you should notice a SelectionStart . Set that to TextBox.Text.Length - 1 to set the insertion point at the end of the text.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I want to insert the text programaticaly.
I am developing for a PDA using the .NET compact framwork.
Everytiem I add data programaticaly as follows:
textBoxTerminal.Text += (string)str;
textBoxTerminal.SelectionStart = textBoxTerminal.Text.Length;
textBoxTerminal.ScrollToCaret();
the cursor jumps to the beginning of the text and then jumps to the end.
How can I avoid this jump to the beginning of the text before I set the caret position?
Thanks.
avivhal
|
|
|
|
|
The fact that you're targeting the .NET CF is something you should've mentioned up-front. We can't help you if you don't give us all the necessary details. The other poster could've avoiding posting about the Append method if he/she knew that you were targeting .NET CF (and either knew off-hand that it wasn't available or bothered to check the documentation before giving faulty information).
Look for my answer on the other responses.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for the answer but I'm using the .NET compact framework in which TextBox.Append does not exist.
Any suggestions for a solution for the .NET compact framework?
Do I have to look for API native code solution?
Thanks.
avivhal
|
|
|
|
|
I'm sorry, didnt know Append wasnt available in all environments. I'm not really sure if there is a simple solution to your problem without the Append method. I'll check around because I'd swear I saw this crop up somewhere else and maybe somedoby came up with a solution that didnt involve the Append method.
I'll Let u know if I find anything.
|
|
|
|
|
Hi, Thanks for your help.
I searched all over the web and could not find a solution/idea how to solve this.
Hope you'll find a solution.
I dont think there is a simple one. I'll probably have to implement a control that uses API dll functions to fix this issue in the .net compact framework.
Please let me know if you find something.
Thanks.
avivhal
|
|
|
|
|
Would it be too "dirty" to use the clipboard and the Paste() method of your Textbox? that seems to do the job.
I dont know if Paste is available to you in your environment...never did anything with PDA's and such.
|
|
|
|
|
The SelectedText , SelectionStart , and SelectionLength properties are defined for TextBoxBase (from which TextBox derives) for the .NET CF, so you can mimic what AppendText does.
What does it do? Use ildasm.exe if you know how to read IL or get a decompiler like .NET Reflector and find out.
Basically, you're looking for something like this:
public class MyTextBox : TextBox
{
public void AppendText(string text)
{
int len = TextLength;
SelectionStart = len;
SelectionLength = len;
SelectedText = text;
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks,
I also noticed that any key event leaves the caret in its position, but when I try to add/append text programaticaly not from within a key event, the caret jumps to the beggining of the TextBox.
Is there any way to add the text from outside those events (that is not by a key clicked but by data received from other data source e.g. a serial port) and keep the caret from jumping to the beginning of the TextBox?
Thanks
avivhal
|
|
|
|
|
That's why you assign SelectionStart then SelectionLength (in that order). If that's not working for you, then you'll need to move the caret by P/Invoking SendMessage and sending EM_SETSEL message (0x00b1) to the Window handle (the Handle property on every control).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Great,
This should do it.
Thanks for your help.
avivhal
|
|
|
|
|
Don't you mean AppendText()? And won't it still be necessary to use SelectionStart? Something along these lines, perhaps:
private static void AddSomeTextToThisTextBoxPlease( TextBoxBase textBox, string someText )
{
int selectionStart = textBox.Text.Length;
textBox.AppendText( someText );
textBox.SelectionStart = selectionStart;
}
Or are you saying AppendText() leaves the cursor where it is? The documentation doesn't seem to say anything regarding that detail.
Matt Gerrans
|
|
|
|
|
I'm using the .net compact framework (I develop this for a pocket pc) in which AppendText does not exist.
It works fine in the full .net framework.
Aviv.
avivhal
|
|
|
|
|
AppendText is the only Append* method defined on or inheritted by TextBox , but it is not defined in the .NET CF.
Normally, no, you do not need to change the selection start since that is handled internally.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Sorry I did not mentioned that I was refering to the .NET CF
My mistake.
Anyhow, I get data from an serial driver I wrote for the PDA and I want to present it in the TextBox.
Since the append method does not exist and I do need to add the data received from the driver to the TextBox, I use :
TextBox.Text += RecievedText;//RecievedText is the data received from the driver
This line of code causes the caret to jump to the beggining of the TextBox.
Thanks for your reply.
avivhal
|
|
|
|
|
Thats exactly the problem I have.
Any key drivven event will respond well.
I wonder what does the .NET framework do to make it work...???
Aviv.
avivhal
|
|
|
|
|
Would it be too "dirty" to use the clipboard and the Paste() method of your Textbox? that seems to do the job.
I dont know if Paste is available to you in your environment...never did anything with PDA's and such.
|
|
|
|
|
It is a bit to "dirty" for me.
I wish I knew what does the .net framework do after a key event?
Then we would have the solution....
Thanks.
avivhal
|
|
|
|
|
Hi,
I have a question to the File.Copy methode.
I use this methode within a timer. Every 10 minutes the timer copies some files to another directory. After that another methode opens and makes some changes in the copied files.
The problem is that the application changes the files before they have been copied yet.
How can I fix this problem?
Marius
|
|
|
|
|
You need to synchronize your methods. When the timer elapses the method is executed in a separate thread that executes asynchronously with the rest of your application. Do get around this there's many classes in the System.Threading namespace you should read about, like a Mutex or a Monitor . C# also defines the lock keyword to lock against a static object (so your copy and modification code should lock against the same object), which compiles down to a Monitor .
The not-so-obvious gotcha is that you should allow queues for the locked object to timeout. If a file copy operation takes 30 minutes for some reason, you could have a couple of requests for the locked object in order to modify the file. Now, maybe this is desirable (to make sure the changes get in there, but to ensure that those changes are updated you really should look into better serialization approaches in case your app dies for some unexpected reason).
Here's an example:
static object sync = new object();
private void Copy()
{
lock (sync)
{
}
}
private void Modify()
{
lock (sync)
{
}
} Again, if you want more control over how your code is synchronized then take a look at the other classes in the System.Threading namespace in the .NET Framework SDK, which is installed by default with VS.NET and is available online at http://msdn.microsoft.com/library[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Use Mutex to wait until the first method finishes the copy process.
You may also use a flag in your class to indicate whether the copy is in-progress or finished and have the modify method wait until the copy is finished. However note that the first solution is clean and neater to maintain the code.
Salil Khedkar [^]
|
|
|
|
|
I've been wandering what is the difference between a richTextBox and a regular (multiline in this case). also, how do I actually use the saveFileDialog control to save the textbox's contents to a file.
|
|
|
|
|
Difference between the two is just about the same as the difference between Notepad and Wordpad. Open them up and play around to see. The RichTextBox support RTF formatted files as well as normal text files.
The SaveFileDialog doesn't do any saving what-so-ever. It's a dialog box that lets the user pick a path and filename that your code uses to do the actual saving of data. Let me repeat this -> YOUR CODE MUST SAVE THE DATA. The SaveFileDialog will not do this for you!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|