|
-
June 6th, 2012, 05:50 AM
#1
date only to be selected
Code:
sqlCommand = new SqlCommand("SELECT date FROM Transactions", sqlConnection);
sqlDataReader = sqlCommand.ExecuteReader();
while (sqlDataReader.Read())
{
comboBoxResult.Items.Add(sqlDataReader["date"].ToString());
}
Please kind coders, this line of code is adding both date and time to the comboBoxResult which i do not want, i only added
date to the database but when retriving it it brings both date and time. I want only the date to be added. Thanks.
-
June 6th, 2012, 08:44 AM
#2
Re: date only to be selected
I'd suggest trying something similar to the following:
Code:
DateTime dtFromSQL;
sqlCommand = new SqlCommand("SELECT date FROM Transactions", sqlConnection);
sqlDataReader = sqlCommand.ExecuteReader();
while (sqlDataReader.Read())
{
dtFromSQL = DateTime.Parse(sqlDataReader["date"].ToString());
comboBoxResult.Items.Add(dtFromSQL.ToShortDateString());
}
Depending on how you want to display your date, once you have it in the DateTime variable, you can format it however you want, short date being the "mm/dd/yyyy" if using the Engish (US) culture.
If this resolves your question, please mark as resolved and rate up. Thanks!
-Quinn
-
June 6th, 2012, 01:30 PM
#3
Re: date only to be selected
Wouldn't you need to use "SELECT [date] FROM Transactions" since date is a reserved word?
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|