|
-
June 5th, 2012, 07:42 AM
#1
Select date from database
Code:
//DateTime date= DateTime.Parse(maskedSearch.Text);
sqlConnection.Open();
sqlDataAdapter = new SqlDataAdapter("SELECT * FROM Transactions WHERE date='" +Convert.ToDateTime(maskedSearch.Text) + "'", sqlConnection);
dataTable = new DataTable();
dataTable.Locale = System.Globalization.CultureInfo.InvariantCulture;
sqlDataAdapter.Fill(dataTable);
dataGridViewSearch.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
dataGridViewSearch.ReadOnly = true;
dataGridViewSearch.DataSource = dataTable;
dataGridViewSearch.Visible = true;
Please i want to select based on the date entered into a maskedTextbox but it's showing error, what can I do to achieve this. Thanks. The error message is:
"Conversion failed when converting date and / or time from character string"
-
June 6th, 2012, 08:50 AM
#2
Re: Select date from database
What is the masked text pulling in when you debug your code? I'm assuming you are doing some sort of globalization/localizing. Convert.ToDateTime naturally assumes the date format is in "mm/dd/yyyy". You can either do DateTime.TryParse, and utilize the date format you are entering, or set the thread of your current culture to invariant right before the sqldataadapter, and see if that works using your convert.todatetime.
Let me know if this works.
If this resolves your issue, please mark as resolved and rate up the post.
Regards,
Quinn
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
|