分类：电脑/网络-程序设计-数据库
问题：如何判断vb.net连数据库后插入数据成功与否程序如下,用的是a 
如下,用的是access,表自由1列,设为主键: Me.OleDbConnection1.Open()        Dim cmd As New OleDbCommand("insert into aaa(姓名) values ('" + Me.TextBox1.Text + "')", Me.OleDbConnection1)        cmd.ExecuteNonQuery()        Me.OleDbConnection1.Close()        MsgBox("ok!")可以正常插入,但是如果有如下,用的是access,表自由1列,设为主键: Me.OleDbConnection1.Open()        Dim cmd As New OleDbCommand("insert into aaa(姓名) values ('" + Me.TextBox1.Text + "')", Me.OleDbConnection1)        cmd.ExecuteNonQuery()        Me.OleDbConnection1.Close()        MsgBox("ok!")可以正常插入,但是如果有重复的数据就会出错请问有什么语句可以在插入失败后判断出来???
回答：Me.OleDbonnection1.Open()Dim cmd As New OleDbCommand("insert into aaa(姓名) values ('" + Me.TextBox1.Text + "')", Me.OleDbConnection1)cmd.ExecuteNonQuery()Me.OleDbConnection1.Close()MsgBox("ok!")在这语句最上面加一句：On Error GoTo lineMe.OleDbConnection1.Open()Dim cmd As New OleDbCommand("insert into aaa(姓名) values ('" + Me.TextBox1.Text + "')", Me.OleDbConnection1)cmd.ExecuteNonQuery()Me.OleDbConnection1.Close()MsgBox("ok!") ("插入失败!")或者用try catch语句：TryMe.OleDbConnection1.Open()Dim cmd As New OleDbCommand("insert into aaa(姓名) values ('" + Me.TextBox1.Text + "')", Me.OleDbConnection1)cmd.ExecuteNonQuery()Me.OleDbConnection1.Close()MsgBox("ok!")Catchmsgbox("插入失败！")