Note that there are some explanatory texts on larger screens.

plurals
  1. POSqlDataAdapter Not Updating
    primarykey
    data
    text
    <p>I am trying to update <code>TableTwo</code> using a <code>DataTable</code> built using <code>TableOne</code>. The relationship between tables is a foreign column called <code>TableOneId</code> inside <code>TableTwo</code>.</p> <p>I used the following code sample to make this work: <a href="http://msdn.microsoft.com/en-us/library/aadf8fk2.aspx" rel="nofollow"><em>Performing Batch Operations Using DataAdapters (MSDN)</em></a></p> <p>The <code>DataTable</code> is populated in another <code>Public Shared</code> function.</p> <p>I can't figure out what is wrong. No error messages are reported. The watch reveals that the <code>DataTable</code> is loaded with data. </p> <p><strong>The <code>DataTable</code> is defined as:</strong></p> <pre><code>Public MyDataTable As New DataTable Public Shared Sub DefineDataTable() Dim ErrorEmail As New ErrorEmailMessageClass With ErrorEmail Try Using connection As New SqlConnection(My.Settings.MyDB) MyDataTable.Columns.Add("ID", Type.GetType("System.Int32")) MyDataTable.Columns.Add("Column1", Type.GetType("System.Int32")) MyDataTable.Columns.Add("Column2", Type.GetType("System.Int32")) MyDataTable.Columns.Add("Column3", Type.GetType("System.Int32")) MyDataTable.Columns.Add("Column4", Type.GetType("System.Int32")) End Using Catch ex As Exception .WriteError("Sub DefineDataTable", ex.Message) End Try End With End Sub </code></pre> <p><strong>But the <code>SqlDataAdapter</code> is not updating:</strong></p> <pre><code>Public Shared Sub UpdateTable() Dim ErrorEmail As New ErrorEmailMessageClass With ErrorEmail Try Using connection As New SqlConnection(My.Settings.MyDB) connection.Open() Dim adapter As New SqlDataAdapter() 'Set the UPDATE command and parameters. adapter.UpdateCommand = New SqlCommand( _ "UPDATE Schema.TableTwo " _ &amp; "SET " _ &amp; "Column1=@Column1, " _ &amp; "Column2=@Column2, " _ &amp; "Column3=@Column3, " _ &amp; "Column4=@Column4 " _ &amp; "WHERE TableOneId=@ID;", connection) adapter.UpdateCommand.Parameters.Add("@Column1", SqlDbType.Int, 4, "Column1") adapter.UpdateCommand.Parameters.Add("@Column2", SqlDbType.Int, 4, "Column2") adapter.UpdateCommand.Parameters.Add("@Column3", SqlDbType.Int, 4, "Column3") adapter.UpdateCommand.Parameters.Add("@Column4", SqlDbType.Int, 4, "Column4") adapter.UpdateCommand.Parameters.Add("@ID", SqlDbType.Int, 4, "ID") adapter.UpdateCommand.UpdatedRowSource = UpdateRowSource.OutputParameters ' Set the batch size. adapter.UpdateBatchSize = 0 ' Execute the update. adapter.Update(MyDataTable) connection.Close() End Using Catch ex As Exception .WriteError("Sub UpdateTable", ex.Message) End Try End With End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload