I have seven fields that need to be populated in seven text boxes. The data is coming from a SQL Compact DB…
Here’s my code so far, but I’m stuck. What do I need to do to populate the text boxes on Form Load… thanks much.
Woody
private void mcContactSubmit_Load(object sender, EventArgs e)
{
// Setup our SQL connection.
SqlCeConnection dataSource = new SqlCeConnection(
@"Data Source=|DataDirectory|\..\..\ContactInformation.sdf;
Persist Security Info=False");
SqlCeDataReader myReader = null;
// Create our command text.
string sqlQuery = String.Format(@"SELECT TOP (1) FirstName, LastName, Title,
Department, Category, Phone, Comments FROM ContactInformation
ORDER BY FirstName DESC");
// Open the SQL connection.
dataSource.Open();
SqlCeCommand myCommand = new SqlCeCommand(sqlQuery, dataSource);
myReader = myCommand.ExecuteReader();
}
You can either use the index or the column name to get the actual data, as follows:
After which, it’s simple assignment to the
TextBox. Otherwise you could also directly insert the Data into theTextBox, but rather not as validation should be done before this in most cases.If you need more help, have a look here:
MSDN – SqlCeDataReader