Click here to Skip to main content
15,896,153 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to compare custom objects in a Dictionary<> Pin
User 66585-Nov-08 9:50
User 66585-Nov-08 9:50 
GeneralRe: How to compare custom objects in a Dictionary<> Pin
ret76796-Nov-08 5:27
ret76796-Nov-08 5:27 
GeneralRe: How to compare custom objects in a Dictionary<> Pin
User 66586-Nov-08 10:25
User 66586-Nov-08 10:25 
Questiondeleting data from a database Pin
postonoh5-Nov-08 7:25
postonoh5-Nov-08 7:25 
QuestionRe: deleting data from a database Pin
Le centriste5-Nov-08 8:33
Le centriste5-Nov-08 8:33 
GeneralRe: deleting data from a database Pin
Guffa5-Nov-08 9:17
Guffa5-Nov-08 9:17 
GeneralRe: deleting data from a database Pin
Le centriste5-Nov-08 9:35
Le centriste5-Nov-08 9:35 
AnswerRe: deleting data from a database Pin
Guffa5-Nov-08 9:37
Guffa5-Nov-08 9:37 
Mo John wrote:
conn.Open();
var dataAdapter = new SqlDataAdapter();
var command = new SqlCommand(select, conn);
dataAdapter.SelectCommand= command;


You don't need a data adapter to put the command in.

Mo John wrote:
var conDS = new ContactDs();


You don't need a data set when you are not reading data.

Mo John wrote:
dataAdapter.Fill(conDS, "Contact");
dataAdapter.DeleteCommand = sqlcmd;
dataAdapter.Update(conDS, "Contact");


There is no reason to read the data into a data set, as you are not using any of it. Also, setting the DeleteCommand property doesn't actually delete anything, it only specifies what to use when something is deleted.

Just execute the command:
using (SqlCommection conn = new SqlConnection("Data Source =(local)\\Openhouse;Initial Catalog=" + _sqlDBName + ";Integrated Security=SSPI")) {
   SqlCommand command = new SqlCommand("DELETE FROM Contact WHERE IDNumber != '156' AND Quality = '40'", conn);
   conn.Open();
   command.ExecuteNonQuery();
}

Note: These five lines replaces all of your code. It also closes the database connection, which you didn't do in your code.

Are the IDNumber and Quality fields really text fields? If they are not, you should use numeric literals instead of string literals in the condition.

Although the != operator is supported by T-SQL, the <> operator is more widely known, and is supported by all SQL implementations.

Despite everything, the person most likely to be fooling you next is yourself.

GeneralRe: deleting data from a database Pin
postonoh5-Nov-08 9:42
postonoh5-Nov-08 9:42 
QuestionGetting application Icon Pin
Dirso5-Nov-08 7:16
Dirso5-Nov-08 7:16 
AnswerRe: Getting application Icon Pin
Colin Angus Mackay5-Nov-08 7:22
Colin Angus Mackay5-Nov-08 7:22 
GeneralRe: Getting application Icon Pin
Dirso5-Nov-08 7:35
Dirso5-Nov-08 7:35 
AnswerRe: Getting application Icon Pin
Henry Minute5-Nov-08 9:50
Henry Minute5-Nov-08 9:50 
GeneralRe: Getting application Icon Pin
Dirso5-Nov-08 10:54
Dirso5-Nov-08 10:54 
QuestionOpen Button Click Event Pin
boiDev5-Nov-08 7:15
boiDev5-Nov-08 7:15 
AnswerRe: Open Button Click Event Pin
Colin Angus Mackay5-Nov-08 7:24
Colin Angus Mackay5-Nov-08 7:24 
AnswerRe: Open Button Click Event Pin
nelsonpaixao5-Nov-08 14:07
nelsonpaixao5-Nov-08 14:07 
QuestionHow to programmatically release resources hold by Thread? Pin
Member 23244835-Nov-08 6:09
Member 23244835-Nov-08 6:09 
GeneralRe: How to programmatically release resources hold by Thread? Pin
led mike5-Nov-08 6:16
led mike5-Nov-08 6:16 
GeneralRe: How to programmatically release resources hold by Thread? Pin
Member 23244835-Nov-08 6:31
Member 23244835-Nov-08 6:31 
GeneralRe: How to programmatically release resources hold by Thread? Pin
led mike5-Nov-08 7:04
led mike5-Nov-08 7:04 
AnswerRe: How to programmatically release resources hold by Thread? Pin
Guffa5-Nov-08 6:54
Guffa5-Nov-08 6:54 
GeneralRe: How to programmatically release resources hold by Thread? Pin
Member 23244835-Nov-08 7:08
Member 23244835-Nov-08 7:08 
GeneralRe: How to programmatically release resources hold by Thread? Pin
Nicholas Butler5-Nov-08 9:46
sitebuilderNicholas Butler5-Nov-08 9:46 
GeneralRe: How to programmatically release resources hold by Thread? Pin
Member 23244835-Nov-08 10:29
Member 23244835-Nov-08 10:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.