2013-12-11 5 views
0

내가있는 DataGridView에 행 필터 기능을 추가하지만, 다음과 같은 오류 메시지가 계속하려고 해요이었다 충돌이 때마다 발생행 필터는 System.Data.EvaluateException와 C#을 응용 프로그램이 처리되지 않은 메시지

System.Data.EvaluateException was unhandled 
Message: An unhandled exception of type 'System.Data.EvaluateException' occurred in System.Data.dll 
Additional information: Cannot perform 'Like' operation on System.Int32 and System.String. 

를 I 내 텍스트 상자에 뭔가를 입력하십시오. 왜 그런가?

의 App.config

<connectionStrings> 
    <add name="SpeedyRent.Properties.Settings.DatabaseConnectionString" 
     connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Database.mdb" 
     providerName="System.Data.OleDb" /> 
</connectionStrings> 

Form1.cs를

// driver no search 

    private void driverNo_TextChanged(object sender, EventArgs e) 
    { 
     BindingSource bs = new BindingSource(); 
     bs.DataSource = dataGridView1.DataSource; 
     bs.Filter = "DriverNo like '%" + driverNo.Text + "%'"; 
     dataGridView1.DataSource = bs; 
    } 
+0

사이드 코멘트를이 시도 : 나는 돈을 다음과 같이 코드입니다 둥지의 무한히 깊은 계층 구조를 만드는 것을 생각하지 않는다. ed BindingSources는 좋은 생각입니다. –

+0

감사합니다. 대신 무엇을 제안 하시겠습니까? 이것이 포럼에서 발견 한 것입니다. – theshizy

+0

Simplest는 항상 하나의 BindingSource를 사용하고, 새로운 BindingSource를 만들기보다는 중첩하여 Filter 속성을 설정합니다. –

답변

0

에서 Form1.cs에

private void driverNo_TextChanged(object sender, EventArgs e) 
    { 

     if (string.IsNullOrEmpty(driverNo.Text)) 
     { 
      ((DataTable)dataGridView1.DataSource).DefaultView.RowFilter = string.Empty; 
      return; 
     } 

     int _driverNo; 

     if (int.TryParse(driverNo.Text,out _driverNo)) 
      ((DataTable)DataGridViews.DataSource).DefaultView.RowFilter = "DriverNo = " + _driverNo; 
     else 
      MessageBox.Show("Invalid driver no."); 
    } 
+0

코드가 변경되지 않았습니까? – theshizy

+0

@ Antoine-LaurentLavoisier 변경은 DriverNo가 % "+ driverNo.Text +"% ";와 같이 ur 오래된 코드를 다시 이것을 reRun 코드로 바꾸고 filter 문자열에서" ' "을 제거합니다. –

+0

감사합니다. 다음과 같은 오류 메시지가 나타납니다. 'System.Data.SyntaxErrorException'형식의 처리되지 않은 예외가 System.Data.dll에서 발생했습니다. – theshizy

관련 문제