0

added checkbox on gridview this method:

<asp:TemplateField> 
<
ItemTemplate> 
<
asp:CheckBox runat="server" ID="CheckBox1" /> 
</
ItemTemplate>

I want to save selected values another table but I did not achive.First I try this code and then I will convert this delete statement to select statement ,it deletes checked value but there is sql exception ID =@ID and keyid=@keyid"; I think this values should be primary key,but I cant set primary key in a table both of them(keyid my primary key now I need this primary key when user select one row ).Please give idea,I tried most of things and tired:(

string connStr = ConfigurationManager.ConnectionStrings["bdConnectionString"].ConnectionString; 
string sql = "Delete From ekleme Where ID =@ID and keyid=@keyid"; 
SqlConnection conn = new SqlConnection(connStr); 
SqlCommand cmd = new SqlCommand(sql, conn); 
cmd.CommandType = 
CommandType.Text; 
SqlParameter keyid = cmd.Parameters.Add("@keyid", SqlDbType.Int); 
SqlParameter ID = cmd.Parameters.Add("@ID", SqlDbType.Int); 
keyid.Value = Session[
"keyid"]; 
string str = ""; 
for (int i = 0; i < GridView1.Rows.Count; i++) 
{
GridViewRow row = GridView1.Rows[i]; 
bool isChecked =((CheckBox)row.FindControl("CheckBox1")).Checked; 
if (isChecked) 
{
str = 
"Seçildi"; 
conn.Open();
ID.Value = GridView1.Rows[i].Cells[0].Text;
cmd.ExecuteNonQuery();
}
}
Response.Write(str);

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by silayse
0

your delete query is not correct

delete statement is:-

DELETE FROM tablename
WHERE LastName='name' AND FirstName='aneme'

DELETE FROM table_name
WHERE some_column=some_value

0

keyid=primary key in my table- coloumn name
@keyid=value
keyid.Value = Session["keyid"];
but may be I am wrong please correct me

0

thanks for reply.Sure I can explain
I added checkbox on gridwiev with itemtemplate actually I need selected datas (primary key is sufficient) this system is petition submission system when student want to add lecture on his schedule advisor can accept or reject his submission.I search this type questions on net and get this sample actuallay it should be work but I dont achive.
my database table:
stuid,stuname,advisor name,addlecture,droplecture,I think primary key stuid and checkbox ID can be primary key because of I see it in a forum
and this code have sql exception now :
SQL exception on cmd.ExecuteNonQuery();
""The parameterized query '(@keyid int,@ID int)Delete From ekleme Where ID =@ID and keyi=@' expects the parameter '@keyid', which was not supplied."
thanks again

This topic has been dead for over six months. 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.