2009-12-31 6 views
0

임 Access 데이터베이스에서 작업 중이며 사용자에게 올바른 정보를 표시 할 수 있도록 아래 코드를 어떻게 해결할 수 있는지 알고 싶습니다. 문제는 oledbcommand가 성공하지 못하면 오류 메시지를 표시하려고합니다. 당신이 함정에 좋아하고 이것은 SQLEXCEPTION으로 시작이 질문에 대한 OLEDB로 변경되었습니다oledbcommand가 성공했는지 확인하는 방법은 무엇입니까?


Try 

Catch se As SpecialException 
    MsgBox("Error1") 

Catch e As Exception ' Catch all other exceptions. 
    MsgBox("General Error") 

End Try 

답변

0

명시 적으로 잡아 줄 것을 예외

 Try 

     cn = New OleDbConnection(" Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\ro.mdb") 
     'provider to be used when working with access database 
     cn.Open() 
     cmd = New OleDbCommand("select * from [Table1]", cn) 

     cmd.CommandText = "insert into [Table1]([LNAME], [FNAME], [MNAME], [POS], [UNAME], [PASS]) values('" + lstname + "','" + frsname + "','" + midname + "','" + post + "','" + usrname + "','" + pword + "')" 


     cmd.ExecuteNonQuery() 

    Catch 
     MsgBox("Either one of the text box is empty or the IDNUMBER entered is already on the database", MsgBoxStyle.Critical) 


    End Try 
0

는 그림 밖으로. 테스트하지 않아서 미안해.

Try  
     ... 
    Catch dbException as OledbException 
     Dim myErrors as OledbErrorCollection = dbException.Errors 
     Dim i as Integer 
      For i = 0 to myErrors.Count - 1 
       MessageBox.Show("Index #" & i & ControlChars.Cr & _ 
        "Error: " & myErrors(i).ToString() & ControlChars.Cr) 
      Next i 
    Finially 
     ... 
관련 문제