I am having some trouble in binding my data from my Access database into my rich text box on my Visual C# form. Here is my code:
private void Form2_Load(object sender, EventArgs e)
{
string connectionString = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= C:\\Documents and Settings\\Harvey\\Desktop\\Test.accdb");
OleDbConnection conGet = new OleDbConnection(connectionString);
OleDbCommand cmdGet = new OleDbCommand();
try
{
//open connection
conGet.Open();
cmdGet.CommandType = CommandType.Text;
cmdGet.Connection = conGet;
cmdGet.CommandText = "SELECT * FROM Paragraph";
richTextBox.Rtf = cmdGet.ExecuteScalar().ToString();
conGet.Close();
MessageBox.Show("Data loaded from Database");
}
catch (Exception ex)
{
//display generic error message back to user
MessageBox.Show(ex.Message);
}
finally
{
//check if connection is still open then attempt to close it
if (conGet.State == ConnectionState.Open)
{
conGet.Close();
}
}
}
When I press the button to load up the form that will contain the rich text box, I get a pop up box saying 'File Format Not Valid' Essentially in my database, there is 1 column that has data in it (1 word per row in that column)
The code I have above was taken from the Internet and other people have had success in using it, i'm just now sure what's going wrong
ExecuteScalar()returns just the first value of the first row - Karsten