1

Hello guys,

I am asking a very simple thing to be done in my project (May be I've forgotten the syntax).........

I've taken a drop-down list in which diff. user-names are coming and added a delete button to delete the full row which contains the selected drop-down list user-name.

I've written the code as............

SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["KMCon"].ToString());
SqlCommand cmd2 = new SqlCommand("delete * from Info where Username=[B]???????[/B], con2);
con2.Open();
cmd2.ExecuteNonQuery();
con2.Close();

What and how should be the syntax to write in the ???????

Thanks in advance........

2
Contributors
5
Replies
8
Views
7 Years
Discussion Span
Last Post by rohand
0

Hello guys,

I am asking a very simple thing to be done in my project (May be I've forgotten the syntax).........

I've taken a drop-down list in which diff. user-names are coming and added a delete button to delete the full row which contains the selected drop-down list user-name.

I've written the code as............

SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["KMCon"].ToString());
SqlCommand cmd2 = new SqlCommand("delete * from Info where Username=[B]???????[/B], con2);
con2.Open();
cmd2.ExecuteNonQuery();
con2.Close();

What and how should be the syntax to write in the ???????

Thanks in advance........

your query will look like below.. try it :
SqlCommand cmd2 = new SqlCommand ("delete from Info where Username = ' " + yourdropdown.SelectedItem.Text + " ' ")

1

your code's working fine but I'm facing a new prob....

In the database, the values are deleted (this should happen).But at the runtime of my application dropdown list shows double values including the one which I've deleted.

For Example........
If entries in dropdown list are.....
KM499
KK499
Kush
Microsoft etc.

And if I delete KK499 then result comes as follows....
KM499
KK499
Kush
Microsoft
KM499
KK499
Kush
Microsoft

What should I do for this...please help me.......

Thanks in advance............

0

your code's working fine but I'm facing a new prob....

In the database, the values are deleted (this should happen).But at the runtime of my application dropdown list shows double values including the one which I've deleted.

For Example........
If entries in dropdown list are.....
KM499
KK499
Kush
Microsoft etc.

And if I delete KK499 then result comes as follows....
KM499
KK499
Kush
Microsoft
KM499
KK499
Kush
Microsoft

What should I do for this...please help me.......

Thanks in advance............

from which sql tables you are filling your combo box ?

1

sql server 2005.......table name is "Info"..........table field is "Username"...and it is a dropdown list....plz reply as soon as possible.....

Edited by KM499: n/a

0

sql server 2005.......table name is "Info"..........table field is "Username"...and it is a dropdown list....plz reply as soon as possible.....

put the code you are binding drop down with value from Info table. Another thing, i can't believe how values are duplicate in drop down as you are using same table (Info) for deleting and binding in drop down.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.