Dr. Rajesh Rolen
Dr. Rajesh Rolen

Reputation: 14285

Save RTF data in My Sql database

Please tell me how to save and show Richtextbox's data in database and retrive it in saved format and which datatype should be used to save that data. i am using vb.net and MY SQL

Upvotes: 0

Views: 2078

Answers (3)

Hemraj Patel
Hemraj Patel

Reputation: 1

Your RTF Data feild should be "Memo".

private void InsertToMemo()
{
  using (OleDbConnection oleDbConn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\AD.mdb"))
  {
    OleDbCommand oleDbCmd = new OleDbCommand("insert into Table2 values(1,'" + this.richTextBox1.Rtf + "')", oleDbConn);
    oleDbCmd.Connection.Open();
    oleDbCmd.ExecuteNonQuery();
  }
}

private void ReadFormMemo()
{
  using (OleDbConnection oleDbConn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\AD.mdb"))
  {
    OleDbCommand oleDbCmd = new OleDbCommand("select Field1 from Table2", oleDbConn);
    oleDbCmd.Connection.Open();
    OleDbDataReader oleDbDataReader = oleDbCmd.ExecuteReader();
    oleDbDataReader.Read();
    this.richTextBox2.Rtf = oleDbDataReader.GetString(0);
  }
}

Upvotes: 0

Ashok Bishnoi
Ashok Bishnoi

Reputation: 199

if your data contains image/icons or some special symbols then its better to go for BLOB otherwise you can go with varchar datatype.

Upvotes: 3

UnDiUdin
UnDiUdin

Reputation: 15394

You can use the BLOB datatype.

Upvotes: 1

Related Questions