Results 1 to 3 of 3

Thread: [RESOLVED] Generate updatecommand parameter

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    88

    Resolved [RESOLVED] Generate updatecommand parameter

    Greetings;

    The subject of generating a tableadapter updatecommand has been beat to death in this forum, but I sure could use some help from the pros. I have been following (trying to) information provided in the MSDN lib, but some little piece of information escapes me.

    First question: I have a DataTable TableAdapter that uses a table join so the command builder will not generate the UpdateCommand parameter. Is it possible to manually generate an UpdateCommand parameter and apply it to an existing TableAdapter? Is that even necessary?

    Second Question: Below is code to generate a DataAdapter and the UpdateCommand for one of my DataTables. I have included only one column to update my DataTable (until I get this thing working). My troubles occur on lines 7 & 8 where I get the error “Option strict does not allow implicit conversions from String to integer”. The parameter statement is requesting this to be “Sourcecolumn as string”. What simple thing am I doing wrong?

    Any advice is appreciated.



    Code:
    1.        Dim dataAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter()
    2.        Dim command As OleDb.OleDbCommand
    3.        Dim parameter As OleDb.OleDbParameter
    
    4.        Dim updateSQL As String = "UPDATE tbl_GreenMatchData SET GTD1 = @GTD1" & "WHERE MatchNumber = @MatchNumber"
    
    5.        'Generate the UpdateCommend 
    6.        command = New OleDb.OleDbCommand(updateSQL, connection)
    7.        command.Parameters.Add("@GTD1", OleDb.OleDbType.Integer, "GTD1")
    
    8.        parameter = command.Parameters.Add("@MatchNumber", OleDb.OleDbType.Integer, "MatchNumber")
    
    9.        parameter.SourceVersion = DataRowVersion.Original
    10.        dataAdapter.UpdateCommand = command
    Last edited by MechEng; Oct 26th, 2007 at 03:02 PM. Reason: add line numbers

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Generate updatecommand parameter

    1st question: Yes, you must manually create update, insert and delete commands if you are to do any update, insert or delete transactions.

    2nd question: you have to use the other overload of the Add method which includes the column data length in its parameters
    Code:
    'If the maxlength property of GTD1 column in your table is 9 characters, you put 9 in the 3rd parameter of the Add function.
    command.Parameters.Add("@GTD1", OleDb.OleDbType.Integer, 9, "GTD1")

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    88

    Re: Generate updatecommand parameter

    That was it! Thank you so much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width