I have a area in my Project where i need to display a title and content in two text boxes. The Data base tables are:
ID | Title | Content
This is what I have so far, I know I am on the right track, I just cant figure out how to get each box to display based on the ID.
Thank you in advance
Rab
ID | Title | Content
This is what I have so far, I know I am on the right track, I just cant figure out how to get each box to display based on the ID.
C#:
private void frmMain_Load(object sender, EventArgs e)
{
try
{
string connStr = ConfigurationManager.ConnectionStrings["sdcAssistDB"].ConnectionString;
OleDbConnection dbConn = new OleDbConnection(connStr);
dbConn.Open();
OleDbCommand dbCommand = new OleDbCommand();
dbCommand.Connection = dbConn;
string query = "select * from JobAid";
dbCommand.CommandText = query;
OleDbDataReader dbReader = dbCommand.ExecuteReader();
while (dbReader.Read())
{
txtTitle1.Text = (dbReader["Title"].ToString());
txtContent1.Text = (dbReader["Content"].ToString());
txtTitle2.Text = (dbReader["Title"].ToString());
txtContent2.Text = (dbReader["Content"].ToString());
}
dbConn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Unable to Connect to Database" + Environment.NewLine + "SDC Assistant will now Close " +ex,
"Critical Database Error!",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
Application.Exit();
}
}
Thank you in advance
Rab