Hi in my code block if i have only one of the text boxes display data it works fine. It doesnt matter whether it is txtPBatch and txtPDate but not both of them at once. when i set it to display for both of my text boxes i get the following error.
System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'. at Benefits_WhosWhereRetirement.Page_Init(Object sender, EventArgs e) in
below is my code:
Thanks in advance!
-Paul
System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'. at Benefits_WhosWhereRetirement.Page_Init(Object sender, EventArgs e) in
below is my code:
Code:
string conString1 = ConfigurationManager.ConnectionStrings["Y5351ConnectionString"].ConnectionString;
SqlConnection sql = new SqlConnection(conString1);
string query = "select top 1 batchID as[BatchID],Convert(varchar(10),date,1)as Date from whoswhere";
SqlCommand cmd = new SqlCommand(query, sql);
SqlDataReader rdr = null;
try
{
sql.Open();
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (rdr.Read())
{
txtPBatch.Text = (string)rdr["BatchID"];
txtPDate.Text = (string)rdr["Date"];
}
}
catch (Exception ex)
{
txtPBatch.Text = ex.ToString();
}
finally
{
if (rdr != null)
rdr.Close();
if (sql.State == ConnectionState.Open)
sql.Close();
}
Thanks in advance!
-Paul