PDA

View Full Version : DeleteCommand in C#


andreasberglind
12-19-03, 06:15 AM
Iīm tryin to get a DeleteCommand for my DataGrid to work, but something is wrong. Can anyone help me? My Command looks like this:

private void lendingGrid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

string movietitle=e.Item.Cells[0].Text;

SqlConnection conn = new SqlConnection(strConnection);

//The SQL command is written on one line in the compiler, of course.
//Itīs also tested in Query Analyzer, and works fine.

SqlCommand command = new SqlCommand("declare @title_ID int
select title_ID = titleID from movietitle where title = '"+movietitle+"'
delete from lending where TitleID = @title_ID", conn);

conn.Open();
command.ExecuteNonQuery();
conn.Close();

//rebind data
getData();
}

My greatest problem is that the DeleteCommand doesnīt seem to run at all.
What else do i nee to do, besides this, and set the DeleteCommand property?

PLEASE HELP!!

/Andreas

andreasberglind
12-24-03, 08:15 AM
I got it to work by setting the button to a linkbutton, but would like it to work with a pushbutton. Could someone tell me what to do?

Merry X-MAS!!!

/Andreas

Shane
12-25-03, 01:14 AM
I got it to work by setting the button to a linkbutton, but would like it to work with a pushbutton. Could someone tell me what to do?

Merry X-MAS!!!

/AndreasMake sure your DataGrid is tagged the correct way. How do you have the column setup?

andreasberglind
12-25-03, 05:47 AM
Make sure your DataGrid is tagged the correct way. How do you have the column setup?


Is this what yopu mean?
<asp:ButtonColumn Text="Return" CommandName="Delete"></asp:ButtonColumn>

thatīs the only thing I can think of. Did you mean something else?