|
-
Feb 27th, 2004, 11:30 PM
#1
Thread Starter
Member
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
-
Mar 2nd, 2004, 04:50 PM
#2
Hyperactive Member
I think you are missing your PARAMETER declaration.
VB Code:
Example:
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:
Sub btnDeleteMem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteMem.Click
Dim myDataGridItem As DataGridItem
Dim strUser As String
Dim objcmd As New OleDbCommand
Dim conn As New OleDbConnection
Dim param As New OldeDbParameter
conn = connectToDB()
objcmd.CommandText = "spDelMembers"
objcmd.CommandType = CommandType.StoredProcedure
objcmd.Connection = conn
For Each myDataGridItem In dgDelMember.Items
If CType(myDataGridItem.FindControl("chkMemDelete"), CheckBox).Checked Then
strUser = CType(myDataGridItem.FindControl("lblUserName"), Label).Text
objcmd.Parameters.Add("@UserName", strUser)
objcmd.ExecuteNonQuery()
objcmd.Parameters.delete 0
End If
Next
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|