1

I want to delete a row corresponding to a particular IP address .. I have written this query :

  string dlt = @"DELETE [LocationIP], [LocationName],[LocationID],
                [NoOfUsers],[MinutesUsed] FROM [LocationInfo] WHERE LocationIP=@ipadd";
  SqlCommand cmd = new SqlCommand(dlt, sqlcon_QOEMetrices);
  cmd.Parameters.Add("@ipadd", SqlDbType.NChar, 15);

  cmd.Parameters["@ipadd"].Value = ipadd;

where ip address is stored in the string variable ipadd This query is not showing any result but even not giving any error...

4 Answers 4

3

You need to execute your command.

Something like:

cmd.ExecuteNonQuery();
Sign up to request clarification or add additional context in comments.

3 Comments

@johntotetwoo - Thanks for the correction. You could have edited that yourself, you know :)
@AdamHouldsworth - as did I... but within the grace period, so we will never know who got it first...
@Oded lol guessing you did otherwise my name would be up there under the edit history I think.
0

Where is the execution of your query?

 cmd.ExecuteNonQuery();

Comments

0

Your SQL is wrong, you don't want a select list in a DELETE statement.

string dlt = @"DELETE FROM [LocationInfo] WHERE LocationIP=@ipadd";
SqlCommand cmd = new SqlCommand(dlt, sqlcon_QOEMetrices);
cmd.Parameters.Add("@ipadd", SqlDbType.NChar, 15);

would suffice. I then assume you are doing somthing like

cmd.ExecuteNonQuery()

Comments

-2

Try this simple query and execute,

 "DELETE FROM LocationInfo WHERE LocationIP=@ipadd"

  SqlCommand cmd = new SqlCommand(dlt, sqlcon_QOEMetrices);
  cmd.Parameters.Add("@ipadd", SqlDbType.NChar, 15);

  cmd.Parameters["@ipadd"].Value = ipadd;
cmd.ExecuteNonQuery();

3 Comments

You need to learn about SQL Injection. Concatenating SQL is not a good idea from a security point of view.
The code the OP posted is actually much better in this regard.
Then perhaps you should delete this answer, as it is showing a bad practice?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.