这个ado.net代码有什么问题?

时间:2016-03-10 07:51:37

标签: vb.net ado.net

我的想法是检查表是否有一行,然后更新当前行,如果表没有行然后插入一个新行,但我得到一个错误(行/列没有数据)在行(如果IsDBNull (dr(0))然后)

        Try
        Dim sql As String = "select * from tblsetting"
        Dim conn As OleDbConnection = New OleDbConnection(constr)
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        conn.Open()
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        dr.Read()
        If IsDBNull(dr(0)) Then
            Dim conn1 As OleDbConnection = New OleDbConnection(constr)
            Dim cmd1 As New OleDbCommand
            conn1.Open()
            cmd1.Connection = conn1
            cmd1.CommandText = "insert into tblsetting (f1,f2,f3) values ('" & ComboBox1.Text & "', '" & ComboBox2.Text & "', '" & ComboBox3.Text & "')"
            cmd1.ExecuteNonQuery()
            cmd1.Dispose()
            conn1.Close()
        Else
            Dim conn1 As OleDbConnection = New OleDbConnection(constr)
            Dim cmd1 As New OleDbCommand
            conn1.Open()
            cmd1.Connection = conn1
            cmd1.CommandText = "update tblsetting set f1 ='" & ComboBox1.Text & "', f2 = '" & ComboBox2.Text & "', f3 = '" & ComboBox3.Text & "' "
            cmd1.ExecuteNonQuery()
            cmd1.Dispose()
            conn1.Close()
        End If
        Me.Close()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

1 个答案:

答案 0 :(得分:-1)

我通过更改行

解决了这个问题
If dr.HasRows = False Then

要:

        global  main
        extern  malloc

section .text
main:
        mov rdi, 40 ; 5*8
        call malloc
        mov qword [array], rax
        mov qword [rax+24], 5 ; mov qword [rax+8], 5 or mov qword [rax+10000] doesn't die on me
        mov rdi, 5
        call malloc


section .bss
        array resq    1