문제

다음 쿼리가 왜 NULL 내가 그 행을 명시 적으로 필터링 할 때 배럴 값 Where 절?

Dim query = From row As dbDataSet.conformalRow In dbDataSet.Tables("conformal") _
            Where Not IsDBNull(row.Cal) AndAlso tiCal_drop.Text = row.Cal _
            AndAlso Not IsDBNull(row.Tran) AndAlso tiTrans_drop.Text = row.Tran _
            AndAlso Not IsDBNull(row.barrel) _
            Select row.barrel
If query.Count() > 0 Then tiBarrel_txt.Text = query(0)

Run-time exception thrown : System.Data.StrongTypingException - The value for column 'barrel' in table 'conformal' is DBNull.

의도 한대로 어떻게 작동하도록 쿼리 / 조건을 다시 작성해야합니까?

도움이 되었습니까?

해결책

기본적으로 강력하게 입력 된 데이터 세트에서 필드가 널이면 속성이 해당 예외를 던집니다. 생성 된 것을 사용해야합니다 Is[Field]Null 방법 :

Dim query = From row As dbDataSet.conformalRow In dbDataSet.Tables("conformal") _
            Where Not row.IsCalNull() AndAlso tiCal_drop.Text = row.Cal _
            AndAlso Not row.IsTranNull() AndAlso tiTrans_drop.Text = row.Tran _
            AndAlso Not row.IsbarrelNull() _
            Select row.barrel
If query.Count() > 0 Then tiBarrel_txt.Text = query(0)

또는 datarow.isnull 메소드 :

Dim query = From row As dbDataSet.conformalRow In dbDataSet.Tables("conformal") _
            Where Not row.IsNull("Cal") AndAlso tiCal_drop.Text = row.Cal _
            AndAlso Not row.IsNull("Tran") AndAlso tiTrans_drop.Text = row.Tran _
            AndAlso Not row.IsNull("barrel") _
            Select row.barrel
If query.Count() > 0 Then tiBarrel_txt.Text = query(0)

다른 팁

이것은 나를 위해 효과가있었습니다.

Dim query = From row As dbDataSet.conformalRow
        In dbDataSet.Tables("conformal") _ 
        Where row.Cal.Length > 0 AndAlso tiCal_drop.Text = row.Cal _ 
            AndAlso row.Tran.Length > 0 AndAlso tiTrans_drop.Text = row.Tran _ 
            AndAlso row.barrel.Length > 0 _ 
        Select row.barrel 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top