Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

TextBox - Problem C#

Posted on 2004-04-12
6
Medium Priority
?
1,286 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 150 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

609 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