hi all. i received the following message :
"Command text was not set for the command object."
when i want to delete selected picture in the page.
i have a radiobuttonlist which has 3 values, and 3 images. the page works like this:
after successful login, the page will display the 3 images which are from the database. this works.
if i want to delete any of the 3 images, i can just simply checked on the respective radio button in the radiobutton list.
the problem comes when i click on the "submit" button below. it displayed the error message "Command text was not set for the command object.", and the image was not deleted.
included below are the codes:
display pictures on pageload:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
rbl_shot.Visible = True
Image1.Visible = True
Image2.Visible = True
Image3.Visible = True
Dim strLoginId As String
strLoginId = Session("strIdSession")
l_name.Text = strLoginId
Try
Dim cnn As New OleDbConnection _
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Server.MapPath("20minutesdb.mdb"))
Dim str As String = "select * from Member where memberID = '" & l_name.Text & "'"
Dim cmd As New OleDbCommand(str, cnn)
Dim dr As OleDbDataReader
cnn.Open()
dr = cmd.ExecuteReader
Do While dr.Read
Dim pic1 As String = dr("imageName").ToString()
Image1.ImageUrl = pic1
Dim pic2 As String = dr("imageName2").ToString()
Image2.ImageUrl = pic2
Dim pic3 As String = dr("imageName3").ToString()
Image3.ImageUrl = pic3
Loop
If Not cmd Is Nothing Then
cmd.Dispose()
End If
If Not dr Is Nothing Then
dr.Close()
End If
If Not cnn Is Nothing Then
cnn.Close()
cnn.Dispose()
End If
Catch
End Try
end sub
this can work...
delete button function:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strSQL As String
Dim cnn As New OleDbConnection _
("Provider=Microsoft.Jet.OLEDB.4.0; data source=c:\Inetpub\wwwroot\0413group1\20MinutesDB.mdb")
If rbl_shot.SelectedValue = "imagename" Then
strSQL = "update member set imagename = 'none' where memberid like '" & l_name.Text & "'"
End If
If rbl_shot.SelectedValue = "imagename2" Then
strSQL = "update member set imagename2 = 'none' where memberid like '" & l_name.Text & "'"
End If
If rbl_shot.SelectedValue = "imagename3" Then
strSQL = "update member set imagename3 = 'none' where memberid like '" & l_name.Text & "'"
End If
'Dim strSQL As String = "UPDATE member SET rbl_shot.selectedvalue = '" & "none" & "' WHERE memberid = '" & l_name.Text & "'"
'execute the command
Dim cmd As New OleDbCommand(strSQL, cnn)
Try
cnn.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
lb_message.Text = ex.Message
Finally
cnn.Close()
End Try
' if not error, goto registerok
If lb_message.Text = "" Then
Response.Redirect("update_success.aspx")
End If
end sub
hope u guys understand what im trying to say. thanks in advance.
"Command text was not set for the command object."
when i want to delete selected picture in the page.
i have a radiobuttonlist which has 3 values, and 3 images. the page works like this:
after successful login, the page will display the 3 images which are from the database. this works.
if i want to delete any of the 3 images, i can just simply checked on the respective radio button in the radiobutton list.
the problem comes when i click on the "submit" button below. it displayed the error message "Command text was not set for the command object.", and the image was not deleted.
included below are the codes:
display pictures on pageload:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
rbl_shot.Visible = True
Image1.Visible = True
Image2.Visible = True
Image3.Visible = True
Dim strLoginId As String
strLoginId = Session("strIdSession")
l_name.Text = strLoginId
Try
Dim cnn As New OleDbConnection _
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Server.MapPath("20minutesdb.mdb"))
Dim str As String = "select * from Member where memberID = '" & l_name.Text & "'"
Dim cmd As New OleDbCommand(str, cnn)
Dim dr As OleDbDataReader
cnn.Open()
dr = cmd.ExecuteReader
Do While dr.Read
Dim pic1 As String = dr("imageName").ToString()
Image1.ImageUrl = pic1
Dim pic2 As String = dr("imageName2").ToString()
Image2.ImageUrl = pic2
Dim pic3 As String = dr("imageName3").ToString()
Image3.ImageUrl = pic3
Loop
If Not cmd Is Nothing Then
cmd.Dispose()
End If
If Not dr Is Nothing Then
dr.Close()
End If
If Not cnn Is Nothing Then
cnn.Close()
cnn.Dispose()
End If
Catch
End Try
end sub
this can work...
delete button function:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strSQL As String
Dim cnn As New OleDbConnection _
("Provider=Microsoft.Jet.OLEDB.4.0; data source=c:\Inetpub\wwwroot\0413group1\20MinutesDB.mdb")
If rbl_shot.SelectedValue = "imagename" Then
strSQL = "update member set imagename = 'none' where memberid like '" & l_name.Text & "'"
End If
If rbl_shot.SelectedValue = "imagename2" Then
strSQL = "update member set imagename2 = 'none' where memberid like '" & l_name.Text & "'"
End If
If rbl_shot.SelectedValue = "imagename3" Then
strSQL = "update member set imagename3 = 'none' where memberid like '" & l_name.Text & "'"
End If
'Dim strSQL As String = "UPDATE member SET rbl_shot.selectedvalue = '" & "none" & "' WHERE memberid = '" & l_name.Text & "'"
'execute the command
Dim cmd As New OleDbCommand(strSQL, cnn)
Try
cnn.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
lb_message.Text = ex.Message
Finally
cnn.Close()
End Try
' if not error, goto registerok
If lb_message.Text = "" Then
Response.Redirect("update_success.aspx")
End If
end sub
hope u guys understand what im trying to say. thanks in advance.