VB.NET2010上的DataGridView

时间:2016-03-14 18:13:47

标签: .net

在vb.net 2010的datagridview中,我想检查一个字符串是否在数据网格中,然后如果不存在,它只会添加该字符串..请帮我怎样。

    Dim idTest As String
    cn.Open()
    Try
        sql = "SELECT * from Balance"
        cmd = New OleDbCommand(sql, cn)
        dr = cmd.ExecuteReader
        While dr.Read
            idTest = dr.GetString(0)
        End While

        If (??????????????????) Then
            sql = "UPDATE Balance SET [ID Number]= '" & TextBox2.Text & "',[Department Fee Balance]= '" & getDeptFeeBalance() & "',[Total Fines] = '" & getTotalFines() & "'"
            cmd = New OleDbCommand(sql, cn)
            cmd.ExecuteNonQuery()
            MsgBox("Balance Updated", vbOKOnly, "System Information")

        Else
            Dim rs As New OleDbCommand("INSERT into Balance([ID Number],[Department Fee Balance],[Total Fines])values('" & TextBox2.Text & "','" & getDeptFeeBalance() & "','" & getTotalFines() & "')", cn)
            rs.ExecuteNonQuery()
            MsgBox("Balance saved!", vbOKOnly, "System Information")
        End If
        cn.Close()

请填写问号

0 个答案:

没有答案