locked
Insert statement not inserting - frustrating RRS feed

  • Question

  • User1216627406 posted

    Please forgive me for bordering you again.

    I am using gridview to insert, delete, update and display records.

    All but the insert statement works.

    when I click to insert, nothing happens, no records are being inserted.

    I followed the example from the following link:

    http://www.aspsnippets.com/Articles/GridView---Add-Edit-Update-Delete-and-Paging-the-AJAX-way.aspx

    Only think I am doing differently on the INSERT statement from the link above is that my table has an identify seed which automatically inserts the requesttypeID while the sample page inserts all records including the CustomerID.

    Can someone please tell me what I am doing wrong?

    Thanks a lot in advance

        Protected Sub AddNewRequestType(ByVal sender As Object, ByVal e As EventArgs)
            Dim RequestType As String = DirectCast(GridView1 _
                    .FooterRow.FindControl("txtrequestType"), TextBox).Text
            Dim emailAdd As String = DirectCast(GridView1 _
            .FooterRow.FindControl("txtEmailAdd"), TextBox).Text
            Dim con As New SqlConnection(strConnString)
            Dim cmd As New SqlCommand()
            cmd.CommandType = CommandType.Text
            cmd.CommandText = "insert into requestTypes(Type_of_Request,senders_Email values(@requestType, @emailAdd);" & _
            "select Type_of_Request, Senders_email from requestTypes"
            cmd.Parameters.Add("@requestType", SqlDbType.VarChar).Value = RequestType
            cmd.Parameters.Add("@emailAdd", SqlDbType.VarChar).Value = emailAdd
            GridView1.DataSource = GetData(cmd)
            GridView1.DataBind()
        End Sub

    Saturday, February 4, 2017 4:09 AM

Answers

  • User-1509636757 posted

    cmd.CommandText = "insert into requestTypes(Type_of_Request,senders_Email values(@requestType, @emailAdd);" & _ "select Type_of_Request, Senders_email from requestTypes"

    On a quick look, there is issue with Insert statement that the small bracket is not closed.

    insert into requestTypes(Type_of_Request,senders_Email) values(@requestType, @emailAdd);" & _ "select Type_of_Request, Senders_email from requestTypes.

    Also, I suggest you transfer the query to Stored Procedure and use it instead of writing inline query.

    hope that helps./.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 4, 2017 4:38 AM

All replies

  • User-1509636757 posted

    cmd.CommandText = "insert into requestTypes(Type_of_Request,senders_Email values(@requestType, @emailAdd);" & _ "select Type_of_Request, Senders_email from requestTypes"

    On a quick look, there is issue with Insert statement that the small bracket is not closed.

    insert into requestTypes(Type_of_Request,senders_Email) values(@requestType, @emailAdd);" & _ "select Type_of_Request, Senders_email from requestTypes.

    Also, I suggest you transfer the query to Stored Procedure and use it instead of writing inline query.

    hope that helps./.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, February 4, 2017 4:38 AM
  • User1216627406 posted

    Great eyes!!!!!!

    WOW, I have been staring at that screen for what seems like forever and could not spot it.

    Thank you so much

    Saturday, February 4, 2017 12:31 PM