473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Formatting TextBox Data

Hi,

I have a multiline TextBox. Text contained in the TextBox will be stored in a SQL Server Database.
How do I format the textBox correctly for database entry?
e.g. How do I ensure that new lines will be added, etc?

Thanks.
May 15 '07 #1
18 2456
kenobewan
4,871 Expert 4TB
Please explain your problem and platform clearly. Thanks.
May 15 '07 #2
Plater
7,872 Expert 4TB
Aside from watching out for single quotes, you should be fine?
(replace each instance of a single quote with two single quotes)
May 15 '07 #3
TRScheel
638 Expert 512MB
Aside from watching out for single quotes, you should be fine?
(replace each instance of a single quote with two single quotes)
And watch for sql injections
May 15 '07 #4
Frinavale
9,735 Expert Mod 8TB
Hi,

I have a multiline TextBox. Text contained in the TextBox will be stored in a SQL Server Database.
How do I format the textBox correctly for database entry?
e.g. How do I ensure that new lines will be added, etc?

Thanks.
You have to screen the text in the TextBox.
You'll have to grab it and filter it to make sure that it is formatted the way that your database expects (eg. is less than the max length). It is also Strongly advised that you screen for malicious database commands that may be executed while running database queries at later dates. You should look for "Drop Table", "Delete", "Select", "Truncate"......
May 15 '07 #5
sorry, the database data is actually displayed in a dataGridView

tried this...
Expand|Select|Wrap|Line Numbers
  1. Eval(queryTextDataGridViewTextBoxColumn).ToString().Replace(System.Environment .NewLine, "<br />"); 
  2.  
But VS2005 gives this error...
Expand|Select|Wrap|Line Numbers
  1. The name 'Eval' does not exist in the current context 
  2.  
May 17 '07 #6
Plater
7,872 Expert 4TB
Eval is not a function in C#, it might be in VB, what language are you using?
May 17 '07 #7
Frinavale
9,735 Expert Mod 8TB
Eval is not a function in C#, it might be in VB, what language are you using?
I've never seen it in VB either.
Maybe its a custom function?
May 17 '07 #8
Plater
7,872 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. Eval(queryTextDataGridViewTextBoxColumn).ToString().Replace(System.Environment .NewLine, "<br />"); 
  2.  
Best I can tell Eval() is used in other languages to take a string and do operations on it, like Eval("1+2") would give you 3. Not sure what he is attempting to do there with it?

If you want the text from a field, get to the correct Cell (DataGridViewCell) and use it's .Value property. So like
Expand|Select|Wrap|Line Numbers
  1. string celltextwithbr=mycell.Value.ToString().Replace(System.Environment .NewLine, "<br />"); 
  2.  
May 17 '07 #9
Frinavale
9,735 Expert Mod 8TB
Best I can tell Eval() is used in other languages to take a string and do operations on it, like Eval("1+2") would give you 3. Not sure what he is attempting to do there with it?

If you want the text from a field, get to the correct Cell (DataGridViewCell) and use it's .Value property. So like
Expand|Select|Wrap|Line Numbers
  1. string celltextwithbr=mycell.Value.ToString().Replace(System.Environment .NewLine, "<br />"); 
  2.  

Yeah JavaScript has an Eval() function that does precisely that.
May 17 '07 #10
thanks.
how do I set it to a certain column in the DataGridView control??

tried the below..
Expand|Select|Wrap|Line Numbers
  1. DataColumn dc = ((DataColumn)dataGridView1.Columns[9].DataGridView);
  2. string myform = dc.ToString().Replace(Environment.NewLine, "<br />");
  3.  
May 17 '07 #11
radcaesar
759 Expert 512MB
Yeah JavaScript has an Eval() function that does precisely that.
Hey Frin,
Its in .NET, We can use it in while we code In-Line

Like This,

<%# DataBinder.Eval(Container.DataItem, "Name") %>
May 17 '07 #12
Plater
7,872 Expert 4TB
You want the text in one particular cell of that column right?
Expand|Select|Wrap|Line Numbers
  1. DataGridViewColumn dc = dataGridView1.Columns[9];
  2. int whichrow = 0;//whichever row you want
  3. string mytext= dataGridView1.Rows[whichrow].Cells[dc.Index].Value.ToString();
  4. string myform = mytext.Replace(Environment.NewLine, "<br />");
  5. //and if you want to set that text BACK:
  6. //assuming the column type is a string
  7. dataGridView1.Rows[whichrow].Cells[dc.Index].Value=myform;
  8.  
May 17 '07 #13
sorry,
every cell row of that column.

Thanks.
May 17 '07 #14
Plater
7,872 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. DataGridViewColumn dc = dataGridView1.Columns[9];
  2. string mytext="";
  3. foreach(DataGridRow dr in dataGridView1.Rows)
  4. {
  5.    mytext= dr.Cells[dc.Index].Value.ToString();
  6.    //you may also chose to have a "<br/>" appended to the end of each row's item here
  7. }
  8. string myform = mytext.Replace(Environment.NewLine, "<br />");
  9.  
  10.  
May 17 '07 #15
get error from VS2005 saying that DataGridRow is inaccessible due to its protection level??
May 17 '07 #16
Plater
7,872 Expert 4TB
get error from VS2005 saying that DataGridRow is inaccessible due to its protection level??
Oops, DataGridViewRow not DataGridRow, but come on, try and do a little of your own leg work.
May 17 '07 #17
I've been trying to get the below working...
Expand|Select|Wrap|Line Numbers
  1.             DataGridViewColumn dc = dataGridView1.Columns[9];
  2.             string mytext = "";
  3.             foreach (DataGridViewRow dr in dataGridView1.Rows)
  4.             {
  5.                 mytext = dr.Cells[dc.Index].Value.ToString();
  6.                 //you may also chose to have a "<br/>" appended to the end of each row's item here
  7.             }
  8.             string myform = mytext.Replace(Environment.NewLine, "<br />");
  9.  
where do I use the string myform?

thanks.
May 18 '07 #18
changed WrapMode in DefaultCellStyle to "True"
and AutoSizeResMode in DataGridView Properties to "All Cells"

This seems to work.

Thanks.
May 18 '07 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kyle | last post by:
Is there an easy way to format data in a textbox control? I have a textbox control bound to a dataset and I would like the datetime data to be formatted as "MM/dd/yyyy" instead of the standard...
2
by: Neil | last post by:
Is there an editable RTF textbox control which allows the user to apply bold, italic, etc.? I tried the Microsoft Rich Textbox Control, but there doesn't seem to be a way to allow the user to...
7
by: BBFrost | last post by:
I'm receiving decimal values from database queries and placing them on a report page. The users want to see the following .... Db Value Display Value 123.3400 123.34...
0
by: d pak | last post by:
Here is a snippit which replicates my issue. I have a datagrid which contains an input textbox on each row, binded on the serverside. However it seems that when I perform a postback to refresh teh...
4
by: Peter Newman | last post by:
the data input app im writing has some 30 + input fields and i want to be able to format them. I know i can use the .validate on each textbox and format the 'string' however this require loads...
7
by: Ryan | last post by:
I have a DataGridView which displays numeric (Int32) data from an underlying database. I want the numbers to be displayed in numeric format "#,###" (with commas). I want to also limit the user so...
5
montzter
by: montzter | last post by:
Hi evryone, I'm having trouble in formatting the inputed data in the text box so that everytime user lost focus it will adjust its value to contain the format (#,####.##). ie user will input...
8
by: Mihai N. | last post by:
I need to format any decimal value so that it is right aligned, thousands It is good to show the info in the format the user prefers. That is language/locale speciffic (CultureInfo in the .NET...
6
by: Tomasz J | last post by:
Hello developers, I bind my TextBox control specyfying a format stored in my application global ApplicationContext object - it has a static string CurrencyFormat property. The problem - this...
12
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I want to plant an Easter Egg in our software. We have a TextBox that is multiline and used to display all sorts of messages on the screen for our operators based on database queries and such. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.