在VB 2015中设置Withblock变量或对象变量

时间:2017-01-01 11:19:07

标签: vb.net

Public Class Form1
    Private ContactsTableBindingSource As Object

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'ContactsTableDataSet.Table' table. You can move, or remove it, as needed.
        Me.TableTableAdapter.Fill(Me.ContactsTableDataSet.Table)
        If ComboBox1.Text = Nothing Then
            Try
                ContactsTableBindingSource.AddNew()
            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 Then
            First_NameTextBox.Text = "unknown"
        End If
        If Last_NameTextBox.Text = Nothing Then
            Last_NameTextBox.Text = "unknown"
        End If
        If AddressTextBox.Text = Nothing Then
            AddressTextBox.Text = "unknown"
        End If
        If Phone_NumberTextBox.Text = Nothing Then
            Phone_NumberTextBox.Text = "unknown"
        End If
        If Email_AddressTextBox.Text = Nothing Then
            Email_AddressTextBox.Text = "unknown"
        End If
        Try
            Me.Validate()
            Me.ContactsTableBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.ContactsTableDataSet)
            MessageBox.Show("The data has been saved", "Information", MessageBoxButtons.OK)
            ContactsTableBindingSource.AddNew()
            First_NameTextBox.Select()
        Catch ex As Exception
            MessageBox.Show(ex.Message)

        End Try
    End Sub

请在代码中建议更正,因为我显示错误"对象变量或Withblock未设置"

0 个答案:

没有答案