Solved

TextBox - Problem C#

Posted on 2004-04-12
6
1,262 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now