Solved

delete image from sql in ado.net

Posted on 2006-07-04
8
242 Views
Last Modified: 2010-04-16
hi there ,

i want to delete image from sql server 2000 ?

i have try this code :

                                                      dbCmd.CommandType = CommandType.Text;
                        dbCmd.CommandText = "update CustDet set logo="+DBNull.Value;
                        dbCmd.Parameters.Clear();
                                  dbCmd.Connection.Open();
                        dbCmd.ExecuteNonQuery();
                        dbCmd.Connection.Close();
but its dosent work ...
how can i remove image from sql ?
thanks....
0
Comment
Question by:Tech_Men
  • 4
  • 3
8 Comments
 
LVL 6

Assisted Solution

by:so3
so3 earned 100 total points
ID: 17038174
Did you try this?  not tested

      dbCmd.CommandType = CommandType.Text;
      dbCmd.CommandText = "update CustDet set logo=NULL";
      dbCmd.Parameters.Clear();
      dbCmd.Connection.Open();
      dbCmd.ExecuteNonQuery();
      dbCmd.Connection.Close();

and also you have to use a primery key to update only the image you want. Your code will update all the rows.
e.g
      dbCmd.CommandText = "update CustDet set logo=NULL WHERE [id]=50";
0
 

Author Comment

by:Tech_Men
ID: 17038649
its not working
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 150 total points
ID: 17038919
I am just curious why you are updating ... I thought you said you wanted to delete it?

Generally to delete a row someone would execute a command such as

DELETE FROM CustDet where [id] = 222

When you say it doesn't work what happens .. perhaps we can help you figure it out but we will need some more information as there are many reasons why the statement may not work. If the code is throwing an exception, that exception would help alot in figuring out whats going on. If it is not throwing an exception what are the pre/post conditions, what is the statement being executed, and lastly what is the expected/observed behavior?

Cheers,

Greg Young
0
 

Author Comment

by:Tech_Men
ID: 17038957
this is the code :

connection.ConnectionString = BL.Conn.ConnString();
                        dbCmd.Connection = connection;

                        dbCmd.CommandType = CommandType.Text;
                        dbCmd.CommandText = "DELETE logo FROM CustDet where CustDetRunID=4";
                                                

                                                      

                        dbCmd.Connection.Open();
                        dbCmd.ExecuteNonQuery();
                        dbCmd.Connection.Close();
not working
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 37

Expert Comment

by:gregoryyoung
ID: 17038962
<quote>
When you say it doesn't work what happens .. perhaps we can help you figure it out but we will need some more information as there are many reasons why the statement may not work. If the code is throwing an exception, that exception would help alot in figuring out whats going on. If it is not throwing an exception what are the pre/post conditions, what is the statement being executed, and lastly what is the expected/observed behavior?
</quote>
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 17038975
also you don't

DELETE logo .. delete deletes the entire row...

it would just be

"DELETE FROM CustDet where CustDetRunID=4";
0
 

Author Comment

by:Tech_Men
ID: 17038989
but it will delete all i want to delete only the logo (image)
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 17039011
ok then you want to update (as I had said in your post you said that you wanted to delete it so there was confusion as to what you were trying to do). Now if you want further help you will need to provide other information (as I described above). Your update could not be working for many reasons .. The further information will let us know which reason it is not working.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now