Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

Question about usage of FormView1_ItemCommand

$
0
0

I'm using Visual Web Developer 2010 Express with SQL Server 2008 Express, VB.

I have a question about usage of FormView1_ItemCommand, see example below. 

    Protected Sub FormView1_ItemCommand(sender As Object, e As System.Web.UI.WebControls.FormViewCommandEventArgs) Handles FormView1.ItemCommand
        Dim sqlConnection As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("conCString").ConnectionString)
        Dim cmd As New SqlCommand
        Dim Ftmp As String = String.Empty
        cmd.CommandType = CommandType.Text
        cmd.Connection = sqlConnection
        If (e.CommandName = "Delete") Then
            Dim querystring As String = "DELETE FROM [Capacitors] WHERE [PART_NUMBER] = N'" & DropDownList1.SelectedItem.Text & "'"
            sqlConnection.Open()
            Dim command As New SqlCommand(querystring, sqlConnection)
            Dim reader As SqlDataReader = command.ExecuteReader()
            sqlConnection.Close()
        End If
    End Sub

It appears that using Formview1_ItemCommand on the VB side overrides anything/everything in the asp side in the DeleteCommand, see below, as the second part does not execute.

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CRAPConnectionString8 %>"
        DeleteCommand="DELETE FROM [Capacitors] WHERE [PART_NUMBER] = @PART_NUMBER; DELETE FROM [PTNOTAB] WHERE [PART_NUMBER] = @PART_NUMBER"

Am I correct in that assumption?  If I am, can I simply move everything to the VB side and remove the asp DeleteCommand or must it remain for some reason?

Note: the above is just an example and is not the complete sub and does "repeat" part of the delete.

Hopefully this is just a simple question, thanks!


Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>