ADO.NET - DataRead Error
- by user560706
Hi,
I am trying to display data from a column in my database onto my rich textbox, but I am getting mixed up between DataSet and DataReader - I know the majority of the code below is correct, I just get two lines containing errors, and I'm not sure why:
// Create a connection string
string ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= C:\\Documents and Settings\\Harley\\Desktop\\Test.accdb");
string SQL = "SELECT * FROM Paragraph";
// create a connection object
SqlConnection conn = new SqlConnection(ConnectionString);
// Create a command object
SqlCommand cmd = new SqlCommand(SQL, conn);
conn.Open();
DataTable dt = new DataTable();
da.Fill(dt); //ERROR
// Call ExecuteReader to return a DataReader
SqlDataReader reader = cmd.ExecuteReader();
foreach(DataRow reader in dsRtn) //ERROR
{
richTextBox = richTextBox.Text + reader[0].ToString();
}
//Release resources
reader.Close();
conn.Close();
}