Results 1 to 2 of 2

Thread: DatagridItem

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2004
    Posts
    47

    DatagridItem

    I am very fustrated and do not understand why i could not get the results as it is. Thus I am wondering do i have create xml is here if i use dataset or datagridItem? It suppose to work out as i have search through the internet site and their code is about the same as mine.. I am really wondering why what is wrong.

    Here is my code below:

    Sub btnDeleteMem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteMem.Click
    Dim myDataGridItem As DataGridItem

    For Each myDataGridItem In dgDelMember.Items

    If CType(myDataGridItem.FindControl("chkMemDelete"), CheckBox).Checked Then

    Dim strUser As String
    strUser = CType(myDataGridItem.FindControl("lblUserName"), Label).Text

    Dim objcmd As New OleDbCommand
    Dim conn As New OleDbConnection

    conn = connectToDB()

    objcmd.CommandText = "spDelMembers"

    objcmd.CommandType = CommandType.StoredProcedure

    objcmd.Connection = conn

    objcmd.Parameters.Add("@UserName", strUser)

    objcmd.ExecuteNonQuery()

    End If
    Next
    End Sub

  2. #2
    Hyperactive Member ARPRINCE's Avatar
    Join Date
    Mar 2003
    Location
    Pinoy in NJ
    Posts
    381
    I think you are missing your PARAMETER declaration.

    VB Code:
    1. Example:
    2. Dim dbParam_Value As SqlParameter = New SqlParameter

    Also, since you are looping thru the grid, you should clear the parameter prior to reading the next record.

    I would do something like the one below since you are using the variables in the same module, I don't think it is efficient to initialize them every loop you make. Don't you get an error somewhere?

    VB Code:
    1. Sub btnDeleteMem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteMem.Click
    2.     Dim myDataGridItem As DataGridItem
    3.     Dim strUser As String
    4.     Dim objcmd As New OleDbCommand
    5.     Dim conn As New OleDbConnection
    6.     Dim param As New OldeDbParameter
    7.     conn = connectToDB()
    8.     objcmd.CommandText = "spDelMembers"
    9.     objcmd.CommandType = CommandType.StoredProcedure
    10.     objcmd.Connection = conn
    11.    
    12.  
    13.     For Each myDataGridItem In dgDelMember.Items
    14.         If CType(myDataGridItem.FindControl("chkMemDelete"), CheckBox).Checked Then
    15.             strUser = CType(myDataGridItem.FindControl("lblUserName"), Label).Text
    16.  
    17.             objcmd.Parameters.Add("@UserName", strUser)
    18.             objcmd.ExecuteNonQuery()
    19.             objcmd.Parameters.delete 0
    20.         End If
    21.     Next
    22. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width