Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

delete image from sql in ado.net

Posted on 2006-07-04
8
Medium Priority
?
253 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 400 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 600 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses

783 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