vb.net中的数据库问题

时间:2016-08-30 11:28:31

标签: database vb.net

我的数据库预览存在问题

Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'Database1DataSet.EmployeDB' table. You can move, or remove it, as needed.
    Me.EmployeDBTableAdapter.Fill(Me.Database1DataSet.EmployeDB)
    If ComboBox1.Text = Nothing Then
        Try
            Me.EmployeDBTableAdapter.Fill(Me.Database1DataSet.EmployeDB)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End If

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If First_NameTextBox.Text = Nothing OrElse
        Last_NameTextBox.Text = Nothing OrElse
        Middle_NameTextBox.Text = Nothing OrElse
        GenderTextBox.Text = Nothing OrElse
        ID__TextBox.Text = Nothing OrElse
        Telephone__TextBox.Text = Nothing Then
        MsgBox("All Fields are Required", MsgBoxStyle.OkOnly, "Error")

    ElseIf GenderTextBox.Text <> "M" And
            GenderTextBox.Text <> "F" And
            GenderTextBox.Text <> "m" And
            GenderTextBox.Text <> "f" Then
        MsgBox("Gender Input Is only M and F.", MsgBoxStyle.OkOnly, "Error")

    Else Try
            Me.Validate()
            Me.EmployeDBBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.Database1DataSet)
            EmployeDBBindingSource.AddNew()
            MessageBox.Show("Data Saved.", "Info", MessageBoxButtons.OK)
            First_NameTextBox.Select()

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End If

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Select Case MsgBox("Are you sure you want to delete the data?", MsgBoxStyle.YesNo, "Info")
        Case MsgBoxResult.Yes
            Try
                ComboBox1.Text = ""
                First_NameTextBox.Clear()
                Last_NameTextBox.Clear()
                Middle_NameTextBox.Clear()
                Telephone__TextBox.Clear()
                ID__TextBox.Clear()
                GenderTextBox.Clear()
                EmployeDBBindingSource.RemoveCurrent()
                Me.Validate()
                Me.EmployeDBBindingSource.EndEdit()
                Me.TableAdapterManager.UpdateAll(Me.Database1DataSet)
            Catch ex As Exception
                MessageBox.Show("Error")
            End Try
        Case MsgBoxResult.No
    End Select
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    ComboBox1.Text = ""
    First_NameTextBox.Clear()
    Last_NameTextBox.Clear()
    Middle_NameTextBox.Clear()
    Telephone__TextBox.Clear()
    ID__TextBox.Clear()
    GenderTextBox.Clear()
    Me.EmployeDBTableAdapter.Fill(Me.Database1DataSet.EmployeDB)
    Me.Validate()
    Me.EmployeDBBindingSource.EndEdit()
    Me.TableAdapterManager.UpdateAll(Me.Database1DataSet)
    EmployeDBBindingSource.AddNew()
End Sub

End Class

我的问题是如何消除&#34; -1&#34;登录ID并且ID中的起点几乎是1000,即使它是第一个数据(我之前制作了数据但我删除了它),我也不知道第一个&#34;保存&#34;不会保存数据,而是创建一个空白区域,第二个保存仅保存并显示正确的数据

1 个答案:

答案 0 :(得分:0)

如果ID字段是自动增量的,那么即使删除了一个ID,也不会再次获得相同的ID。

很抱歉其他问题,但我没有得到它们