I’m new in c#.
I need to add a Find_Click button which has the functions that can help me to count the number of Rows in a database Table when l key in the value inside the textbox, then display the counted value.
The problem is, the number of rows could not be counted because the values inside are Datetime.
Could anyone help me fix my code? Here it is:
private void Find_Click(object sender, EventArgs e)
{
string search = FindDateTime.Text;
int result = 0;
DataRow[] returnedRows;
returnedRows = RetailCamDataSet1.Tables["pcPeopleCountingValue"]
.Select("ValueDateTime='" + search + "'");
result = returnedRows.Length;
if (result > 0)
{
DataRow RetailCamDataRow1;
RetailCamDataRow1 = returnedRows[0];
MessageBox.Show(returnedRows.Length.ToString());
}
else
{
MessageBox.Show("No such Record.");
}
}
The following line should change to this:
Provided your
searchvariable has the DateTime in the right format.From your comment. You can’t use
BETWEENin theSelect()method, instead you could do something like:You could also use dataset lambda extensions, see : https://stackoverflow.com/a/3924140/368070