Solved

TextBox - Problem C#

Posted on 2004-04-12
6
1,267 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
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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

827 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