2013-07-11 46 views
0

這裏是我的代碼:爲什麼我的數據網格正在向db輸入數據,但我的文本框不是?

Imports System.Data 
Imports System.Data.SqlClient 



Public Class Form2 
    Private conn As New SqlConnection("Data Source=wal1sql1;Initial Catalog=ValueTracker;Integrated Security=True") 
    Private da As New SqlDataAdapter("SELECT * FROM ValueSources", conn) 
    Private ds As New DataSet 
    Private cmb As New SqlCommandBuilder(da) 


    'Declaration 
    Public Property AllowDBNull As Boolean 


    Private Sub AddNullAllowedColumn() 
     Dim column As DataColumn 
     column = New DataColumn("ValueSourceID", _ 
      System.Type.GetType("System.Int32")) 
     column.AllowDBNull = True 

     ' Add the column to a new DataTable. 
     Dim table As DataTable 
     table = New DataTable 
     table.Columns.Add(column) 
    End Sub 


    Private Sub ValueSourcesBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles ValueSourcesBindingNavigatorSaveItem.Click 
     da.UpdateCommand = cmb.GetUpdateCommand 

     da.Update(ds.Tables("ValueSources")) 


    End Sub 

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
     Try 
      da.Fill(ds, "ValueSources") 

      ValueSourcesDataGridView.DataSource = ds.Tables("ValueSources") 
     Catch 

     End Try 

     'TODO: This line of code loads data into the 'ValueTrackerDataSet.ValueSourceAvailability' table. You can move, or remove it, as needed. 
     Me.ValueSourceAvailabilityTableAdapter.Fill(Me.ValueTrackerDataSet.ValueSourceAvailability) 
     'TODO: This line of code loads data into the 'ValueTrackerDataSet.ValueSources' table. You can move, or remove it, as needed. 
     Me.ValueSourcesTableAdapter.Fill(Me.ValueTrackerDataSet.ValueSources) 
     'Me.ValueSourcesTableAdapter.GetData() 

    End Sub 

    Private Sub ServiceTypeIdTextBox_TextChanged(sender As Object, e As EventArgs) 
    End Sub 

    Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem.Click 

    End Sub 

    Private Sub ValueSourcesBindingNavigator_RefreshItems(sender As Object, e As EventArgs) Handles ValueSourcesBindingNavigator.RefreshItems 

    End Sub 

    Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click 
     da.UpdateCommand = cmb.GetUpdateCommand 

     da.Update(ds.Tables("ValueSources")) 

     MsgBox("Successfully Saved") 
    End Sub 

    Private Sub ValueSourceIDTextBox_TextChanged(sender As Object, e As EventArgs) 

    End Sub 

    Private Sub ValueSourceNameTextBox_TextChanged(sender As Object, e As EventArgs) 
     da.UpdateCommand = cmb.GetUpdateCommand 

     da.Update(ds.Tables("valuesources")) 
    End Sub 

    Private Sub ValueSourceDescriptionTextBox_TextChanged(sender As Object, e As EventArgs) 
     da.UpdateCommand = cmb.GetUpdateCommand 

     da.Update(ds.Tables("valuesources")) 
    End Sub 

    Private Sub ServiceTypeIdTextBox_TextChanged_1(sender As Object, e As EventArgs) 
     da.UpdateCommand = cmb.GetUpdateCommand 

     da.Update(ds.Tables("valuesources")) 
    End Sub 

    Private Sub UseCaseIDTextBox_TextChanged(sender As Object, e As EventArgs) 
     da.UpdateCommand = cmb.GetUpdateCommand 

     da.Update(ds.Tables("valuesources")) 
    End Sub 

    Private Sub CreateDateDateTimePicker_ValueChanged(sender As Object, e As EventArgs) 
     da.UpdateCommand = cmb.GetUpdateCommand 

     da.Update(ds.Tables("valuesources")) 
    End Sub 

    Private Sub CreateByTextBox_TextChanged(sender As Object, e As EventArgs) 
     da.UpdateCommand = cmb.GetUpdateCommand 

     da.Update(ds.Tables("valuesources")) 
    End Sub 

    Private Sub ValueSourceDescriptionTextBox_TextChanged_1(sender As Object, e As EventArgs) Handles ValueSourceDescriptionTextBox.TextChanged 

    End Sub 

    Private Sub ValueSourceDescriptionLabel_Click(sender As Object, e As EventArgs) 

    End Sub 

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
     Me.Hide() 
     MainMenu.Show() 
    End Sub 
End Class 

我的問題是:

爲什麼正在將數據輸入數據網格我入分貝,但我的文本框都沒有?

某處有斷開連接,我無法弄清楚。

回答

0

通常這樣的..

da.UpdateCommand = cmb.GetUpdateCommand 

da.ExecuteNonQuery 
相關問題