Click here to Skip to main content
15,887,175 members
Home / Discussions / C#
   

C#

 
GeneralRe: While we're on the subject of language constructs Pin
Kentamanos11-Feb-04 16:54
Kentamanos11-Feb-04 16:54 
GeneralRe: While we're on the subject of language constructs Pin
Tom Clement11-Feb-04 17:07
professionalTom Clement11-Feb-04 17:07 
GeneralRe: While we're on the subject of language constructs Pin
Werdna13-Feb-04 12:23
Werdna13-Feb-04 12:23 
GeneralStoring RichText data in Access Database Field Pin
bjulien11-Feb-04 15:51
bjulien11-Feb-04 15:51 
GeneralRe: Storing RichText data in Access Database Field Pin
John Kuhn11-Feb-04 16:29
John Kuhn11-Feb-04 16:29 
GeneralRe: Storing RichText data in Access Database Field Pin
Heath Stewart12-Feb-04 3:35
protectorHeath Stewart12-Feb-04 3:35 
GeneralRe: Storing RichText data in Access Database Field Pin
bjulien12-Feb-04 8:03
bjulien12-Feb-04 8:03 
GeneralRe: Storing RichText data in Access Database Field Pin
Heath Stewart12-Feb-04 8:36
protectorHeath Stewart12-Feb-04 8:36 
First of all, you don't need to use RichTextBox.Rtf.ToString - it already is a string.

Second, the error in your query expression is because you're not encoding the string. If you use parameterized queries, you'll find this is taken care of for you and is a much better design, especially when you have to do batch updates:
OleDbConnection conn = new OleDbConnection("your connection string");
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = "UPDATE notes SET notetext = @notetext WHERE notekey = 1";
OleDbParameter notetextParam = cmd.Parameters.Add("@notetext",
  OleDbType.LongVarWChar, 4000);
try
{
  notetextParam.Value = txtData.Rtf;
  cmd.ExecuteNonQuery();
}
finally
{
  if (conn != null && (conn.State & ConnectionState.Open) != 0)
    conn.Close();
}
With ADO.NET, do not use string concatentation to avoid problems like this. Using parameterized queries are far more robust and provide many other features like being able to use an OleDbCommandBuilder to create INSERT, UPDATE, and DELETE statements that correspond to a provided simple SELECT statement, and more.

Notice also that I did not include my parameter in quotes in the query string. ADO.NET will take care of this as well.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Storing RichText data in Access Database Field Pin
bjulien12-Feb-04 10:25
bjulien12-Feb-04 10:25 
GeneralExplicit abstract methods. Pin
krisp11-Feb-04 15:29
krisp11-Feb-04 15:29 
GeneralRe: Explicit abstract methods. Pin
Kentamanos11-Feb-04 15:52
Kentamanos11-Feb-04 15:52 
GeneralRe: Explicit abstract methods. Pin
krisp11-Feb-04 16:21
krisp11-Feb-04 16:21 
GeneralRe: Explicit abstract methods. Pin
Kentamanos11-Feb-04 16:45
Kentamanos11-Feb-04 16:45 
GeneralRe: Explicit abstract methods. Pin
krisp11-Feb-04 17:06
krisp11-Feb-04 17:06 
GeneralRe: Explicit abstract methods. Pin
Kentamanos11-Feb-04 17:41
Kentamanos11-Feb-04 17:41 
GeneralFile Backup Pin
Demo36011-Feb-04 14:50
Demo36011-Feb-04 14:50 
GeneralRe: File Backup Pin
Heath Stewart12-Feb-04 3:31
protectorHeath Stewart12-Feb-04 3:31 
GeneralRe: File Backup Pin
Anonymous16-Feb-04 5:53
Anonymous16-Feb-04 5:53 
GeneralRe: File Backup Pin
Demo36016-Feb-04 7:33
Demo36016-Feb-04 7:33 
GeneralRe: File Backup Pin
Heath Stewart16-Feb-04 8:50
protectorHeath Stewart16-Feb-04 8:50 
GeneralSurround Sound speaker localization Pin
Matt Frear11-Feb-04 13:00
Matt Frear11-Feb-04 13:00 
GeneralRe: Surround Sound speaker localization Pin
Heath Stewart12-Feb-04 3:28
protectorHeath Stewart12-Feb-04 3:28 
GeneralRe: Surround Sound speaker localization Pin
Matt Frear16-Feb-04 11:11
Matt Frear16-Feb-04 11:11 
Generalclose button on control box of form Pin
visiontec11-Feb-04 11:34
visiontec11-Feb-04 11:34 
GeneralRe: close button on control box of form Pin
Heath Stewart11-Feb-04 12:18
protectorHeath Stewart11-Feb-04 12:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.