P
Paul Yanzick
Hello,
I'm having some issues pulling a datetime object from a database and am
looking for any suggestions I can get.
I have written a function to make querying specific fields in a table as
generic as possible. The function is below:
private string GetFieldValue(string IDKey, string FieldName)
{
SqlConnection Connection = new
SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand Command=new SqlCommand("Select " + FieldName + " from
issueescalation where IDKey='" + IDKey + "'",Connection);
SqlDataAdapter Adapter=new SqlDataAdapter(Command);
Connection.Open();
string RetValue=(string)Adapter.SelectCommand.ExecuteScalar();
Connection.Close();
return RetValue;
}
The problem is when I query a datetime field. I keep getting an error
message saying the specified cast is invalid. The date field is populated,
and I am able to modify the SQL command and pull components of the datetime
such as the year, but keep getting the same error. Any suggestions? If you
need more info, please let me know.
Thanks
Paul
I'm having some issues pulling a datetime object from a database and am
looking for any suggestions I can get.
I have written a function to make querying specific fields in a table as
generic as possible. The function is below:
private string GetFieldValue(string IDKey, string FieldName)
{
SqlConnection Connection = new
SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand Command=new SqlCommand("Select " + FieldName + " from
issueescalation where IDKey='" + IDKey + "'",Connection);
SqlDataAdapter Adapter=new SqlDataAdapter(Command);
Connection.Open();
string RetValue=(string)Adapter.SelectCommand.ExecuteScalar();
Connection.Close();
return RetValue;
}
The problem is when I query a datetime field. I keep getting an error
message saying the specified cast is invalid. The date field is populated,
and I am able to modify the SQL command and pull components of the datetime
such as the year, but keep getting the same error. Any suggestions? If you
need more info, please let me know.
Thanks
Paul