I am developing question paper generator for student in windows application with c# language in visual . right now stuck on this problem , i have a rich Text box in the form where we can paste maths quadratic equations from Ms word or word pad . now i wants that pasted quadratic equation must save in database and must display in crystal report .(saving is properly working with ole object but cant able to show in crystal report) I go through many website and forums and many other options like changing datatypes of db with memo , with text interpreation to RTF text and ole object and saving equations in byte form but haven't get the answer yet , there is nothing shown in crystal report from rich text box i tried with blob also but not seen any . here is my Database in access : ID = Number , Question = Text , Equations = OLE object ( quadratic equation saving from rich text box) Thank you , Hope will get the answer soon.
code for saving in database
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(rtf);
try{
OleDbConnection oldb = new OleDbConnection("connection string");
oldb.Open();
string query = "insert into table_temp(question , objects , object2) values( @questions , @obj , @obj2)";
OleDbCommand cmd = new OleDbCommand(query, oldb);
cmd.Parameters.AddWithValue("@questions", richTextBox1.Text);
cmd.Parameters.AddWithValue("@obj", bytes);
cmd.Parameters.AddWithValue("@obj2", richTextBox2.Rtf);
cmd.ExecuteNonQuery();
MessageBox.Show("save", "save", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
catch(Exception ex)
{
MessageBox.Show("Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
// code for displaying in report .
DataSet ds_temp = new DataSet();
string query_temp = "select * from table_temp ";
OleDbCommand cmd_temp = new OleDbCommand(query_temp, oldb);
cmd_temp.ExecuteNonQuery();
OleDbDataAdapter adp_temp = new OleDbDataAdapter(cmd_temp);
adp_temp.Fill(ds_temp);
mathematical_formulla.temp_report obj = new mathematical_formulla.temp_report();
ReportDocument rptDoc = new ReportDocument();
reportform rpt = new reportform();
DataTable dt = new DataTable();
dt = ds_temp.Tables[0];
obj.SetDataSource(dt);
rpt.crystalReportViewer1.ReportSource = obj;
rpt.Show();
Thanks !! Now i got the answer , and also wants to share this .
First of all take the rich text box and connect them with word pad
richTextBox2.SelectedRtf = Properties.Resources.Document;
write the Maths equation and reflect back to RTB than take a screen shot of RTB in picture box by following code .
public static Bitmap RtbToBitmap(RichTextBox rtb)
{
rtb.Update(); // Ensure RTB fully painted
Bitmap bmp = new Bitmap(rtb.Width, rtb.Height);
using (Graphics gr = Graphics.FromImage(bmp))
{
gr.CopyFromScreen(rtb.PointToScreen(Point.Empty), Point.Empty, rtb.Size);
}
return bmp;
}
now the picture box having an image and convert this image into byte array and store in DB and this equation will reflect into Crystal report also .
thanks you .