Hi All,
I have a multi textbox in a windows application with a button that saves the content of textbox into a database
I need to save it into the database as I wrote it in the textbox so that when I need to display it from that field into the textbox an to appear it as it was writeen from the same textbox(multi line)
example of the textbox contents( three lines)
1- this is the first line
2- this is the second line
3- this is the third line
I need this lines to update them in the field and to display them in the same textbox in the same manner.
I would appreciate If any one could help
with advanced thanks
thanks John Penn for the help
Guest UserPosted Dec 31, 2008, 1:01 PM
omar ahmedPosted Jan 2, 2009, 1:28 PM
hi,
the code I have posted works fine, but the problem I have countered was using field of datatype text not memo .
thanks
omar ahmedPosted Jan 2, 2009, 1:23 PM
Hi,
I code I posted before this post works nice . My problem was I thought before writing the application That I will be not able to retreive them in manner of multiline
but now It works fine. thanks for the guidance
Guest UserPosted Jan 1, 2009, 5:33 PM
Try creating a stored procedure or parameterized query to do the insert, and add a SqlParameter object to the SqlCommand object's Parameters collection.
omar ahmedPosted Jan 1, 2009, 3:10 AM
thanks John Penn
I have wrote the appliction and Retrieved as you said
I have coded like this :
private void button1_Click(object sender, EventArgs e)
{
string InsertSQL = "INSERT INTO Test(MultiLineText)Values('"+textBox1.Text+"')";
cmd = new OleDbCommand(InsertSQL , cn);
cmd.Parameters.AddWithValue("@MultiLineText", textBox1.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Saved to the Table successfully");
}
private void button2_Click(object sender, EventArgs e)
{
try
{
DataRow[] dr = ds.Tables["Test"].Select("No='" + textBox2.Text + "'");
if (dr.Length > 0)
{
DataRow row = dr[0];
textBox1.Text = row["MultiLineText"].ToString();
}
else
{
MessageBox.Show("Sorry Number " + textBox2.Text + " Doesnot exist", "Record Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}