|
Hi everybody,
it seems to be so simple but ...
I want to store the contents of a multiline textbox into SQL-Server or MSDE.
Using the ntext or text field of the databases does not show the expected results.
The Database truncates all text comming from multiline textbox after a space or CRLF charakter.
The DataSet in memory stores the correct contents but the Database itself truncates the rest.
Is it because the multiline textfield is an array of string[] ?
do I have to iterate over the string field ?
Why does the DataSet does it right but the Database not ?
Thanks in advance
fracalifa
|
|
|
|
|
That depends on how your sending the information to the database. Are you using a parameterized query? What does your code that sends the info to the database look like? On top of that, you must store a single string, not an array of them.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
That' the code I am using for
private void data_update()
{
SqlDataAdapter adapter = new SqlDataAdapter();
string upd_CommandString = "UPDATE database_name SET textboxA=@textboxA WHERE id = " + id.ToString();
SqlCommand updateCommand = new SqlCommand();
updateCommand.CommandText = upd_CommandString;
updateCommand.Connection = conn;
adapter.UpdateCommand = updateCommand;
updateCommand.Parameters.Add(new SqlParameter("@textboxA", SqlDbType.NText,16,"textboxA"));
DRow.BeginEdit();
...
...
DRow["textboxA"]= this.txt_Multiline_Textbox.Text; // assign the multiline TB to DataRow object
...
...
DRow.EndEdit();
DB.open(ref conn); // connect Database
adapter.Update(Ds,"database_name");
DB.close(); // close Database
}
// The Database query simply looks like --> SELECT * FROM database_name WHERE id = 123
Whithin the Ds everything is fine, but not in the database field.
Using the database fieldtype NVarChar,4000 instead - everything looks fine -
Where is the fault ?
Thanks
fracalifa
|
|
|
|
|
The problem appears to be this line:
updateCommand.Parameters.Add(new SqlParameter("@textboxA", SqlDbType.NText,16,"textboxA"));
Your telling it that the parameter is a SQL NText field that is 16 bytes long. The type and size value you give it must match the definitions in your database table. If not, you run into screwy problems like this.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello All,
I have a form that has 4 textboxes on it and a button. Initially the button is disabled but as soon as someone types/changes text in one of the text boxes I would like to enable the button. How can I detect changes in a text box ? Do I need to watch out for changes in each individual textbox or is it possible for the form to notify me that one of the textboxes changed ? Thanks in advance...
-Peter
|
|
|
|
|
Hi Peter,
I think the simplest solution is to add one EventHandler for the KeyPress-Event for all 4 textboxes.
For example the eventhandler can look like this:
<br />
private void txtTextBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) {<br />
<br />
}<br />
To make sure that all 4 Textboxes calls this handler, simply click at the textbox (Forms-Designer in VS.NET) and select the flash-symbol from the properties page. There you have an entry called KeyPress and there you can select the method above.
Now you can call a method in this handler to verify the content of the textbox and do what you want with the button.
I hope this helps you.
Sebastian
P.S: Sorry for grammar and spelling...
|
|
|
|
|
To add the posting of Mr. SeMartens. If you want to do some specific task in the keyPress event of a perticular textBox , You can easily do the same. Below example illustrate the same.
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextBoxesKeyPress);
this.textBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextBoxesKeyPress);
this.textBox3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextBoxesKeyPress);
this.textBox4.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextBoxesKeyPress);
private void TextBoxesKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(sender == this.textBox1)
{
}
else if(sender == this.textBox2)
{
}
else if(sender == this.textBox3)
{
}
else if(sender == this.textBox4)
{
}
}
Do revert back whether it could solve your purpose or not
|
|
|
|
|
Hello guys,
This should have been simple, but im pretty stuck here.
I have an simple XML file where i want to change the content of the file. The file is as follows
config.xml
<Config>
<ReportServer>0</ReportServer>
<LastReportDate>20041214</LastReportDate>
</Config>
is there a simple way to change the content of the elements fx. <ReportServer> to a 1 instead of a 0 ??
Cheers
Ronni
|
|
|
|
|
yes there is simple way, use System.Xml.XmlDocument . Why don't you try XML forums?
David
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Here's some sample code for you:
using System;
using System.Xml;
class Class1
{
static void Main(string[] args)
{
string xmlpiece = @"<Config>
<ReportServer>0</ReportServer>
<LastReportDate>20041214</LastReportDate>
</Config>
";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlpiece);
XmlNode node = doc.SelectSingleNode("/Config/ReportServer");
node.InnerText = "1";
Console.WriteLine(doc.OuterXml);
}
}
Yes, even I am blogging now!
|
|
|
|
|
Why my program process a file in 6 minute and if I reprocess same file, it take 6 seconds. I am runing on xp operating system.
Thank you
|
|
|
|
|
"process" can mean anything! What, EXACTLY, are you talking about?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
My program read customer file consist of 9000 records. I process each record and it takes around 6 minutes to process those records, if I re-process this file again, it will take only 6 second to process same input file. It seems like XP operating system keep every thing in memory.
|
|
|
|
|
Hi
I have some strings and for each one I would like to call a specific function.
eg.
bla -> func()
blah -> func2()
etc..
I know I could use a hashtable, except c# doesn't have an eval function (as far as I know). How could it be done? At the moment I've got a switch for this, but this must not be the fastest way.
Thanks
|
|
|
|
|
You should check into System.Reflection[^] namespace, in particular, look at the MethodInfo[^] class, it contains a method called Invoke[^] that will allow you to dynamically call a method based on it's name and some additional information.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Thanks very much, I've read a bit about it and come up with this code:
#region Using directives<br />
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Reflection;<br />
using System.Text;<br />
<br />
#endregion<br />
<br />
namespace ConsoleApplication1<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
Type t = typeof(Program);<br />
object [] argsg = new object [] {100, 184};<br />
t.InvokeMember("ComputeSum", BindingFlags.Default | BindingFlags.InvokeMethod<br />
| BindingFlags.Static, null, null, argsg);<br />
}<br />
public static void ComputeSum(int num1, int num2)<br />
{<br />
Console.WriteLine(num1 + num2);<br />
Console.ReadKey();<br />
return;<br />
}<br />
}<br />
}<br />
Why does it generate a "MissingMethodException was unhandled" error?
Thanks again
|
|
|
|
|
I have a Object that inherits from ListViewItem. However, when a add this instance to the ListView, there is no text or whatever in it. If I add a SubItem, then the second column is populated but the first still not.
How can i display the value on my ListViewItem in the first column ?.
Thanks in advance
Well.. later
|
|
|
|
|
When you create your ListViewItem object, the string you pass as a parameter is what will be displayed in the first column.
For example
<br />
ListViewItem item = new ListViewItem("Text that will be displayed in the first column");<br />
item.SubItem.add("Text that will be displayed in the second column");<br />
Hope this helps
Hugo Migneron
|
|
|
|
|
We can pass a ListViewItem to the items.add methods of the ListView, I can't pass a string since a need to put object into the listview.
Well.. later
|
|
|
|
|
I am not sure i understand correctly what you are saying, can you post your code?
Hugo Migneron
|
|
|
|
|
lstServerExplorer.Items.Clear();<br />
foreach( XmlNode node in xn)<br />
{<br />
strProvider = node.ChildNodes[0].InnerText.ToString();<br />
strServer = node.ChildNodes[1].InnerText.ToString();<br />
strDatabase = node.ChildNodes[2].InnerText.ToString();<br />
strUser = node.ChildNodes[3].InnerText.ToString();<br />
strPassword = node.ChildNodes[4].InnerText.ToString();<br />
itm = new ConnectionItem(strProvider, strServer, strDatabase, strUser, strPassword);<br />
lstServerExplorer.Items.Add(itm);<br />
}
Where itm is an instance of a class that inherits from ListViewItem.
Well.. later
|
|
|
|
|
I would say you should call the base ListViewItem constructor in the ConnectionItem consctuctor.
public ConnectionItem(strProvider, strServer, strDatabase, strUser, strPassword):base([whatever you want to display in your first column])
Hope this helps!
Hugo Migneron
|
|
|
|
|
You helped me find the solution. I have used base.Text and it finnally work, thank you so much.;)
Well.. later
|
|
|
|
|
I have a small app that I run on the files in the directory (pulls strings out of .resx files). I want to add a param to that app to do the sub dirs. How can I get all .resx files from the sub directories given a root directory? My guess is to use the Directory.GetDirectories but I bet I have to do it recursively right? Simpler way of doing it?
Any code samples?
Thanks
Darren
|
|
|
|
|
Anonymous wrote:
My guess is to use the Directory.GetDirectories but I bet I have to do it recursively right? Simpler way of doing it?
That is the simpler way of doing it. Write a function that takes a path as a parameter. This function will process all the files in that path. Then, it gets the list of subdirectories in that path and, one-by-one, calls itself with the new paths from that list.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|