none
Tableadapter and need to pass in additional value within insert statement. RRS feed

  • Question

  • I've created windows form project written in VB.net  The table that I'm using is structured as follows.

    CommentID (int, identity) not null
    CommentDesc (nchar 100) not null
    UserID (nchar 50) not null

    In creating a tableadapter via "Add TableAdapter" my Select, Upate, and Delete statement works just fine.

    My problem is with the Insert statement.  On my Select statement I'm only bringing back CommentID and CommentDesc.
    What I wish to accomplish is on an insert statement I need to pass in the UserID but keep getting error stating that parameter is already being used.

    My code looks like below:

        Private Sub cmdSaveComment_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSaveComment.Click
            Me.tableadapterComment.Adapter.InsertCommand.Parameters.AddWithValue("@UserID", Environment.UserName.ToString)
            Me.tableadapterComment.Update(Me.dsComments.Comments)
        End Sub

    Below is what the Insert Command shows within Query Builder:

    INSERT INTO Comments (CommentDesc, UserID)
    VALUES        (@CommentDesc,@UserID)

    Would appreciate any assistance anyone could provide.

    Thanks

    Wednesday, June 9, 2010 9:19 PM

All replies

  • Hello,

     

    After some research, I cannot repro this problem at my side.   If it is convenient for you, could you please send me a demo project for further troubleshooting?   My mail address is v-micsun@microsoft.com.    Thank you very much!

     

    Have a great day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, June 10, 2010 6:55 AM
    Moderator
  • Hi,

     

    I am writing to check the status of the issue on your side.  Would you mind letting us know how is the problem now? 

     

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, June 15, 2010 1:38 AM
    Moderator