'Cannot perform 'Like' operation on System.Single and System.String.'

  • Thread starter Thread starter Ravi Kumar12233
  • Start date Start date
R

Ravi Kumar12233

Guest
Hello ,

i am building a win form app using access database as data-source , and in the search button of my winform i have this code"

private void searchAccessDatabase()
{
if (string.IsNullOrEmpty(KeywordTextBox.Text.Trim()))
{
Refreshdata();
return;
}
string strkeyword = KeywordTextBox.Text.Trim().ToString();

StringBuilder sb = new StringBuilder();
sb.AppendFormat("(Convert(ID,'System.String') LIKE '" + "{0}" + "')", strkeyword);
sb.AppendFormat("OR (Customer_Name LIKE '*" + "{0}" + "*')", strkeyword);
sb.AppendFormat("OR (Complaint_Number LIKE '*" + "{0}" + "*')", strkeyword);
sb.AppendFormat("OR (Size LIKE '*" + "{0}" + "*')", strkeyword);
sb.AppendFormat("OR (Material_Number LIKE '*" + "{0}" + "*')", strkeyword);
sb.AppendFormat("OR (Nature_Of_Problem LIKE '*" + "{0}" + "*')", strkeyword);
sb.AppendFormat("OR (Spool_Type LIKE '*" + "{0}" + "*')", strkeyword);
string strFilter = sb.ToString();
material_Return_DataBindingSource.Filter = strFilter;

if (material_Return_DataBindingSource.Count != 0)
{
dataGridView1.DataSource = material_Return_DataBindingSource;
}
else
{
MessageBox.Show("No Records Found", "Search Result", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);

Refreshdata();
return;
}
}

But during search to simply test i entered a column data which is not provided above , so i got the error message saying

'Cannot perform 'Like' operation on System.Single and System.String.'

So if i enter a keyword of a column which is not provided above the exception should be "can not access the provided keyword " and return . Can Anybody kindly help me with the code..please.

Here is the sample data table:1614161.png

Continue reading...
 
Back
Top