Last post Jan 08, 2013 08:05 AM by wavemaster
Jan 08, 2013 06:58 AM|Resumepod|LINK
Hi I am using this code this is fetching record Successfully but when i want to delete this record via button it gives error Invalid object name 'Image'. can anyone solve this problem?
Partial Class admin_Images
Dim id As String
Dim cn As New SqlConnection
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
id = Request.QueryString("ID")
pics.SelectCommand = "Select * From slider_pics Where ID='" & Trim(id) & "'"
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If .State = Data.ConnectionState.Open Then .Close()
.ConnectionString = ("Data Source=184.108.40.206;Initial Catalog=Ikidedb;User ID=gthkiutrvh;Password=fhghgh")
Catch ex As Exception
Label1.Text = ("An error accourd. Please contact to admin")
.CommandText = "DELETE Image FROM slider_pics WHERE ID=" & Trim(id) & ""
.Connection = cn
dr = .ExecuteReader
Label1.Text = ("Deleted.")
Catch ex As Exception
Label1.Text = (ex.Message)
Jan 08, 2013 07:06 AM|Resumepod|LINK
Image is column name , Table name is slider_pics
Jan 08, 2013 07:07 AM|ManikandanUlagu|LINK
the way of deleting query is incorrect. CommandText
= "DELETE Image FROM slider_pics WHERE ID="
pls tell you want to delete the entire row or particuler column.
Jan 08, 2013 07:08 AM|NadeemZee|LINK
if you wants to delete a column value then have to run a update query.
update slider_pics set Image='' where ID=" & Trim(id) & ""
or if you wants to delete entire row the qurey become
delete from slider_pics where ID=" & Trim(id) & ""
Jan 08, 2013 07:24 AM|Resumepod|LINK
Jan 08, 2013 08:05 AM|wavemaster|LINK
Wanted to share something with you on how I implemented row delete in my site. I am in no way a expert on the matter, but I think I found an elegant solution.
Rather than delete a record I simply flag it as IsDeleted = true
Whenever I need to display information from a table I can choose to display deleted records or not.
The plus side is I can keep track of things to determine all sorts of interesting facts such as how many users sign up and quit after a certain amount of time.
Plus restoring information is as easy as removing the flag.