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

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 + " ' ")

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

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 ?

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.