Link to home
Start Free TrialLog in
Avatar of karra
karra

asked on

TextBox - Problem C#

Hello,

Lang : C# Web Application.
Control : Normal TextBox (No fancy)
DB : Access Database.

I know that i am missing something here.. but i would appreciate if someone can help me in this regard. I am new to .NET.

I have a problem with the multiline textbox. The problem is: It does not allow me to have any special characters like Single Quotes, Double Quotes, #, Enter key, etc. With the enter key, when i press the enter key it does only take all the char till that enter key was pressed, after which all other text would not be stored or retrieved.

What i Need is:

I should be able to save and retrieve all the data typed in the textbox including all special chars (which i mentioned above).

Thx
Karra
Avatar of _TAD_
_TAD_



I think you may want to switch to a rich-text box.  An rtb is a lot more friendly with the information you want to provide.  A multi-line text box is really just a list view that let's you select portions of lines instead of a whole line.
The TextBox control does except all the characters you mention, to except tabs set the AcceptTabs property to true. You may also need to set the AcceptReturn to true if your form contains a default button.

The access data base is probably where you are dropping the characters, I'm no Access expert but the Access documnetation should tell you how to handle the special characters.
You can handle TextBox problems as AdrianJMartin says, but about Access, how are you going to insert or update the value in the database? Can you paste that part for us? I think you are building your sql as text?
Avatar of karra

ASKER

Guys,

I think it is the problem of the access too but i don;t how to make access accept all these char. I wanted access to consider all these char until u leave the textbox as one text for that field.

I actually want this code to work for both Insert and Updates. I am building my SQL as string and then passing the string to the insert and update statement just like any other string variables. when i debug i get all the text as required but when it runs the executenonqury() method it kicks me out saying::

Syntax error in string in query expression ': " = ',# (gives the list of all the special char here like shown)

THis is what i have written:

private void btOK_Click(object sender, System.EventArgs e)
{
string txtwkreqreq = ValidateItems(txtwkreq.Text);
string sql4 = "INSERT INTO WorkOrd (WorkRequested) Values (" + txtwkreqreq + ")";
OleDbConnection conn = null;
try
{
conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " +
            "Data Source=" + Server.MapPath("../workorder/DB/workorder-DB.mdb"));
conn.Open();
               
OleDbCommand cmd = new OleDbCommand(sql4,conn);
cmd.ExecuteNonQuery();
}
finally
{
if (conn != null)  conn.Close();
}
}


public string ValidateItems(string Item)
{
string nullvalue = "null";
if (Item == "")
{
     return (nullvalue);
}
else
{
return ("'" + Item + "'");
}
}

I think for quotes you need to replace ' with '' ( single quote with DOUBLE single quote ) and " with "" ( double quote with Double double quote)

string txtwkreqreq = ValidateItems(txtwkreq.Text);
txtwkreqreq  = txtwkreqreq.Replace( @"""" , @"""""").Replace( @"'",@"''");


Also try( note the sqaure brackets arround the text, I think Access take the contents as a Literal so you can include any charcter, but please Don't quote me on this I'm NOT a Access fan!!!).
string sql4 = "INSERT INTO WorkOrd (WorkRequested) Values ([" + txtwkreqreq + "])";
ASKER CERTIFIED SOLUTION
Avatar of caner_elci
caner_elci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial