Solved

TextBox - Problem C#

Posted on 2004-04-12
6
1,271 Views
Last Modified: 2008-01-16
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
0
Comment
Question by:karra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 22

Expert Comment

by:_TAD_
ID: 10808577


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.
0
 
LVL 5

Expert Comment

by:AdrianJMartin
ID: 10812532
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.
0
 
LVL 4

Expert Comment

by:caner_elci
ID: 10816406
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?
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:karra
ID: 10816656
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 + "'");
}
}

0
 
LVL 5

Expert Comment

by:AdrianJMartin
ID: 10821587
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 + "])";
0
 
LVL 4

Accepted Solution

by:
caner_elci earned 50 total points
ID: 10821718
You better use cmd.Parameters property..

OleDbCommand cmd = new OleDbCommand( "INSERT INTO WorkOrd (WorkRequested) Values ( @WorkRequested )", conn );
cmd.Parameters.Add( "@WorkRequested", txtwkreqreq );
cmd.ExecuteNonQuery();

This is the best way to run a command.. This way, you can insert any type of data...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question