sqldatasource control insert command to fire after a button is clicked.

Last post 02-09-2008 12:39 PM by xbhavesh. 2 replies.

Sort Posts:

  • sqldatasource control insert command to fire after a button is clicked.

    02-09-2008, 3:33 AM
    • Member
      42 point Member
    • gnuts4lunch
    • Member since 03-29-2005, 3:50 PM
    • Posts 99

    Hi, I

     have created a table with 2 columns and 5 textboxes..these textboxes will fill 5 parameters out of 6 in an sqldatasource control .

    The 6th parameter is the logged in users userid.

    1) I want the sqldatasource controls insert command to be fired on the click of a button i create on the form.

    How can i do this? what do i write in the buttons on_click event?

    2) How can i call the sqldatasource control in the submit buttons on_click event?

    I saw this on 4guysfromrolla..a similar thing didnt work on my form..

     

    SqlDataSource DataSource = (SqlDataSource)CreateUserWizardStep2.ContentTemplateContainer.FindControl("InsertExtraInfo");

     

    Thanks


  • Re: sqldatasource control insert command to fire after a button is clicked.

    02-09-2008, 9:19 AM
    Answer
    • Star
      8,559 point Star
    • siva_sm
    • Member since 12-20-2007, 11:03 AM
    • Posts 1,256

    Call SqlDataSource.Insert() to invoke whatever specified in SqlDataSource.InsertCommand

    Mark replies as answers if they helped you solve the problem.
  • Re: sqldatasource control insert command to fire after a button is clicked.

    02-09-2008, 12:39 PM
    Answer
    • Member
      291 point Member
    • xbhavesh
    • Member since 03-08-2007, 12:15 PM
    • Posts 238

    In you button click

    Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)

    Dim cmd As SqlCommand = New SqlCommand("INSERT INTO YourTable (LoggedInUser) Values(@LoggedInUser)", conn)

    cmd.Parameters.AddWithValue("@LoggedInUser", 1)           ' This ill enter 1 as the the value in your table for the user bing logged in. you can set it to be anything else.

    conn.Open()

    cmd.ExecuteReader()

    conn.Close()

    -------------------------
    Anything is possible.

    If Post.Solved.Problem Then
    " Mark As Answer "
    End If
Page 1 of 1 (3 items)