EDN Admin
Well-known member
can anyone tell me whats wrong with my update command?
when i attempt to update i get an error saying theres an error in my update statement...
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Public <span style="color:Blue; Shared <span style="color:Blue; Function getTable() <span style="color:Blue; As DataTable
connect()
updatableAdapter = <span style="color:Blue; New OleDb.OleDbDataAdapter(<span style="color:#A31515; "SELECT * FROM Table1", connection)
<span style="color:Green; Create the InsertCommand.
<span style="color:Blue; Dim command <span style="color:Blue; As <span style="color:Blue; New OleDb.OleDbCommand(<span style="color:#A31515; "INSERT INTO Table1 VALUES(@id, @number, @subjectName, @years, @birthYear)", connection)
<span style="color:Green; Add the parameters for the InsertCommand.
command.Parameters.Add(<span style="color:#A31515; "@id", OleDb.OleDbType.<span style="color:Blue; Integer, 5, <span style="color:#A31515; "id")
command.Parameters.Add(<span style="color:#A31515; "@number", OleDb.OleDbType.VarChar, 50, <span style="color:#A31515; "number")
command.Parameters.Add(<span style="color:#A31515; "@subjectName", OleDb.OleDbType.VarChar, 50, <span style="color:#A31515; "subjectName")
command.Parameters.Add(<span style="color:#A31515; "@years", OleDb.OleDbType.<span style="color:Blue; Integer, 3, <span style="color:#A31515; "years")
command.Parameters.Add(<span style="color:#A31515; "@birthYear", OleDb.OleDbType.<span style="color:Blue; Integer, 4, <span style="color:#A31515; "birthYear")
updatableAdapter.InsertCommand = command
<span style="color:Green; Create the UpdateCommand.
command = <span style="color:Blue; New OleDb.OleDbCommand( _
<span style="color:#A31515; "UPDATE Table1 SET id = @id, number = @number, subjectName = @subjectName, years = @years, " & _
<span style="color:#A31515; "birthYear = @birthYear WHERE id = @oldID", connection)
<span style="color:Green; Add the parameters for the UpdateCommand.
command.Parameters.Add(<span style="color:#A31515; "@id", OleDb.OleDbType.<span style="color:Blue; Integer, 5, <span style="color:#A31515; "id")
command.Parameters.Add(<span style="color:#A31515; "@number", OleDb.OleDbType.VarChar, 50, <span style="color:#A31515; "number")
command.Parameters.Add(<span style="color:#A31515; "@subjectName", OleDb.OleDbType.VarChar, 50, <span style="color:#A31515; "subjectName")
command.Parameters.Add(<span style="color:#A31515; "@years", OleDb.OleDbType.<span style="color:Blue; Integer, 3, <span style="color:#A31515; "years")
command.Parameters.Add(<span style="color:#A31515; "@birthYear", OleDb.OleDbType.<span style="color:Blue; Integer, 4, <span style="color:#A31515; "birthYear")
<span style="color:Blue; Dim parameter <span style="color:Blue; As OleDb.OleDbParameter = command.Parameters.Add( _
<span style="color:#A31515; "@oldID", OleDb.OleDbType.<span style="color:Blue; Integer, 5, <span style="color:#A31515; "id")
parameter.SourceVersion = DataRowVersion.Original
updatableAdapter.UpdateCommand = command
<span style="color:Green; Create the DeleteCommand.
command = <span style="color:Blue; New OleDb.OleDbCommand( _
<span style="color:#A31515; "DELETE FROM Table1 WHERE id = @id", connection)
<span style="color:Green; Add the parameters for the DeleteCommand.
command.Parameters.Add( _
<span style="color:#A31515; "@id", OleDb.OleDbType.<span style="color:Blue; Integer, 5, <span style="color:#A31515; "id")
parameter.SourceVersion = DataRowVersion.Original
updatableAdapter.DeleteCommand = command
<span style="color:Blue; Dim dt <span style="color:Blue; As <span style="color:Blue; New DataTable
updatableAdapter.Fill(dt)
<span style="color:Blue; Return dt
<span style="color:Blue; End <span style="color:Blue; Function
[/code] <hr class="sig thanks for any help
View the full article
when i attempt to update i get an error saying theres an error in my update statement...
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Public <span style="color:Blue; Shared <span style="color:Blue; Function getTable() <span style="color:Blue; As DataTable
connect()
updatableAdapter = <span style="color:Blue; New OleDb.OleDbDataAdapter(<span style="color:#A31515; "SELECT * FROM Table1", connection)
<span style="color:Green; Create the InsertCommand.
<span style="color:Blue; Dim command <span style="color:Blue; As <span style="color:Blue; New OleDb.OleDbCommand(<span style="color:#A31515; "INSERT INTO Table1 VALUES(@id, @number, @subjectName, @years, @birthYear)", connection)
<span style="color:Green; Add the parameters for the InsertCommand.
command.Parameters.Add(<span style="color:#A31515; "@id", OleDb.OleDbType.<span style="color:Blue; Integer, 5, <span style="color:#A31515; "id")
command.Parameters.Add(<span style="color:#A31515; "@number", OleDb.OleDbType.VarChar, 50, <span style="color:#A31515; "number")
command.Parameters.Add(<span style="color:#A31515; "@subjectName", OleDb.OleDbType.VarChar, 50, <span style="color:#A31515; "subjectName")
command.Parameters.Add(<span style="color:#A31515; "@years", OleDb.OleDbType.<span style="color:Blue; Integer, 3, <span style="color:#A31515; "years")
command.Parameters.Add(<span style="color:#A31515; "@birthYear", OleDb.OleDbType.<span style="color:Blue; Integer, 4, <span style="color:#A31515; "birthYear")
updatableAdapter.InsertCommand = command
<span style="color:Green; Create the UpdateCommand.
command = <span style="color:Blue; New OleDb.OleDbCommand( _
<span style="color:#A31515; "UPDATE Table1 SET id = @id, number = @number, subjectName = @subjectName, years = @years, " & _
<span style="color:#A31515; "birthYear = @birthYear WHERE id = @oldID", connection)
<span style="color:Green; Add the parameters for the UpdateCommand.
command.Parameters.Add(<span style="color:#A31515; "@id", OleDb.OleDbType.<span style="color:Blue; Integer, 5, <span style="color:#A31515; "id")
command.Parameters.Add(<span style="color:#A31515; "@number", OleDb.OleDbType.VarChar, 50, <span style="color:#A31515; "number")
command.Parameters.Add(<span style="color:#A31515; "@subjectName", OleDb.OleDbType.VarChar, 50, <span style="color:#A31515; "subjectName")
command.Parameters.Add(<span style="color:#A31515; "@years", OleDb.OleDbType.<span style="color:Blue; Integer, 3, <span style="color:#A31515; "years")
command.Parameters.Add(<span style="color:#A31515; "@birthYear", OleDb.OleDbType.<span style="color:Blue; Integer, 4, <span style="color:#A31515; "birthYear")
<span style="color:Blue; Dim parameter <span style="color:Blue; As OleDb.OleDbParameter = command.Parameters.Add( _
<span style="color:#A31515; "@oldID", OleDb.OleDbType.<span style="color:Blue; Integer, 5, <span style="color:#A31515; "id")
parameter.SourceVersion = DataRowVersion.Original
updatableAdapter.UpdateCommand = command
<span style="color:Green; Create the DeleteCommand.
command = <span style="color:Blue; New OleDb.OleDbCommand( _
<span style="color:#A31515; "DELETE FROM Table1 WHERE id = @id", connection)
<span style="color:Green; Add the parameters for the DeleteCommand.
command.Parameters.Add( _
<span style="color:#A31515; "@id", OleDb.OleDbType.<span style="color:Blue; Integer, 5, <span style="color:#A31515; "id")
parameter.SourceVersion = DataRowVersion.Original
updatableAdapter.DeleteCommand = command
<span style="color:Blue; Dim dt <span style="color:Blue; As <span style="color:Blue; New DataTable
updatableAdapter.Fill(dt)
<span style="color:Blue; Return dt
<span style="color:Blue; End <span style="color:Blue; Function
[/code] <hr class="sig thanks for any help
View the full article