Bind Variable to DetailView on Insert

Last post 10-19-2006 1:03 PM by mahalie. 4 replies.

Sort Posts:

  • Bind Variable to DetailView on Insert

    10-18-2006, 10:13 PM
    • Loading...
    • mahalie
    • Joined on 01-21-2006, 1:10 AM
    • Posts 24

    I have a fairly straight forward datagrid but I removed one field called 'UserID' because I grab that from User.Identity.Name. It's probably very basic, but how do I set the value to the correct field? I would think I assign it during the ItemInserting event...but what exactly do I assign it to? dataView1.DataKey ?? somethin?

     

     

     

  • Re: Bind Variable to DetailView on Insert

    10-18-2006, 10:40 PM
    Answer
    • Loading...
    • mahalie
    • Joined on 01-21-2006, 1:10 AM
    • Posts 24
    Stick out tongue Okay, I think I figured part of it out:
        Protected Sub dvRSVP_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles dvRSVP.ItemInserting
            Dim userName As String = User.Identity.Name.ToString
            e.Values("userID") = userName
        End Sub
     
    But now I get a 'Data type mismatch in criteria expression.' error. I'm sure it's the bit above because if I comment it out then the error goes away (but of course userID is blank). This writes to an Access database, the userID field is set to Text there and I can enter the same value manually. Also, the insert parameter seems to be correct:

    <asp:Parameter Name="userID" Type="String" />

    Any ideas? I'm able to assign the userName to a label and it looks okay. Here's the datasource insert command:

    InsertCommand="INSERT INTO [tblRSVP] ([userID], [adults], [kids], [pumpkins], [food]) VALUES (?, ?, ?, ?, ?)"

    Filed under: , ,
  • Re: Bind Variable to DetailView on Insert

    10-18-2006, 10:45 PM
    • Loading...
    • rexlin
    • Joined on 07-17-2006, 8:43 AM
    • Posts 1,751

    Hi,mahalie:

    I think you can add the unique key of the records to the DataKeys properties.

    Here is some tutorials:

    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.basedatalist.datakeys.aspx



    Best Regards,
    __________________________________________________
    Sincerely,
    Rex Lin
    Microsoft Online Community Support

    This posting is provided "AS IS" with on warranties, and confers no rights.
  • Re: Bind Variable to DetailView on Insert

    10-19-2006, 12:51 PM
    • Loading...
    • mahalie
    • Joined on 01-21-2006, 1:10 AM
    • Posts 24
    That didn't seem to apply to what I'm doing. Can someone give me a specific example assigning a value programmatically during the iteminserting event? Any ideas why I'm getting a data type mismatch in criteria expression error?
  • Re: Bind Variable to DetailView on Insert

    10-19-2006, 1:03 PM
    Answer
    • Loading...
    • mahalie
    • Joined on 01-21-2006, 1:10 AM
    • Posts 24

    Ah, I finally answered my own question.  The mismatch error was due to my deleting the primary key from the SQL insert statement and not removing it from the insert parameters. Using e.Values("fieldName") = in the iteminserting event of the details view works perfectly!!

Page 1 of 1 (5 items)
Microsoft Communities
Page view counter