i have written a query to update the table but its not updating the table please help me if some buddy can...
protected void accept1_Click(object sender, EventArgs e)
{
con.Open();
Label Label1 = (Label)reqlist.FindControl("Label1");
SqlCommand cmd=new SqlCommand("update friends set friendstatus='Y' where myid='" + Label1 + "' AND friendid='" + Session["myid1"] + "'",con);
cmd.ExecuteNonQuery();
Response.Write("thanx");
con.Close();
}
Loading

Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jun 25, 2013, 2:52 AM EDT
sorry for the wrong code . i did not check that. now try following code i checked that.
in aspx:
in cs:
protected void accept1_Click(object sender, EventArgs e)
{
con.Open();
Button b = (Button)sender;
DataListItem row = (DataListItem)b.NamingContainer;
Label ID = (Label)row.FindControl("Label1");
SqlCommand cmd = new SqlCommand("update friends set friendstatus='Y' where myid='" + ID.Text + "' AND friendid='" + Session["myid1"] + "'", con);
cmd.ExecuteNonQuery();
Response.Write("thanx");
con.Close();
}
for second button
protected void not_Click(object sender, EventArgs e)
{
con.Open();
Button c = (Button)sender;
DataListItem row = (DataListItem)c.NamingContainer;
Label ID = (Label)row.FindControl("Label1");
SqlCommand cmd = new SqlCommand("update friends set friendstatus='N' where myid='" + ID.Text + "' AND friendid='" + Session["myid1"] + "'", con);
cmd.ExecuteNonQuery();
Response.Write("thanx");
con.Close();
}
hope it will help you
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jun 24, 2013, 8:13 AM EDT
aspx page code and detail cs code.
Iftikar HussainRank #423 · 5.9K reputationPosted Jun 24, 2013, 11:33 PM EDT
You need to use Label1.Text
Label1 will contain the definition of Label control not the actual value
protected void accept1_Click(object sender, EventArgs e)
Please let me know if you need more information
Regards,
Iftikar
Remember to click "Mark as Answer" on the post, if it helps you.
Gopal Ji Singh39 reputationPosted Jun 25, 2013, 12:22 AM EDT
when m using lable1.text then m getting error like in attachment...
Iftikar HussainRank #423 · 5.9K reputationPosted Jun 25, 2013, 1:02 AM EDT
Please tell me what is reqlist. is it a DataGrid or any other control? Can you provide the .aspx code also
Regards,
Iftikar
Gopal Ji Singh39 reputationPosted Jun 25, 2013, 1:14 AM EDT
reqlist is a DataLsit control where we have two button 1 is accept and 2 is not now.....and my problem is on accept button...rest find into the attachment
Iftikar HussainRank #423 · 5.9K reputationPosted Jun 25, 2013, 1:22 AM EDT
I am not able to see any attachement.Can you please attach it
Regards,
Iftikar
Gopal Ji Singh39 reputationPosted Jun 25, 2013, 1:27 AM EDT
please find the attachment...
Gopal Ji Singh39 reputationPosted Jun 25, 2013, 1:28 AM EDT
reqlist is a DataLsit control where we have two button 1 is accept and 2 is not now.....and my problem is on accept button...rest find into the attachment
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jun 25, 2013, 1:44 AM EDT
check this code:
in aspx on accept button code:
in cs button click code:
protected void accept1_Click(object sender, EventArgs e)
{
con.Open();
int index = Convert.ToInt32((sender as Button).CommandArgument);
Label ID = ((Label)reqlist.Items[index].FindControl("Label1"));
//Label ID = (Label)reqlist.FindControl("Label1");
SqlCommand cmd=new SqlCommand("update friends set friendstatus='Y' where myid='" + ID.Text + "' AND friendid='" + Session["myid1"] + "'",con);
cmd.ExecuteNonQuery();
Response.Write("thanx");
con.Close();
}
hope it will help you
Iftikar HussainRank #423 · 5.9K reputationPosted Jun 25, 2013, 2:00 AM EDT
Modify your datalist as shown below
and your code behind
protected void DataListItemCommand(object source, DataListCommandEventArgs e)
Regards,
Iftikar
Remember to click "Mark as Answer" on the post, if it helps you.
Gopal Ji Singh39 reputationPosted Jun 25, 2013, 2:02 AM EDT
Its a zip file...Please find the attachment.....name is Page
Gopal Ji Singh39 reputationPosted Jun 25, 2013, 2:30 AM EDT
after your code m getting this error...please find the attachment
Sunny SharmaRank #223 · 11.1K reputationPosted Jun 25, 2013, 2:45 AM EDT
Can you please mention the error that you're getting? If you're not getting any error, try putting your query execution block inside try...catch block like:
-----------------------
try
{
cmd.ExecuteNonQuery()
}
catch(exception ex)
{
Response.Write(ex.Message); //handle the error
}
---------------------------------
Gopal Ji Singh39 reputationPosted Jun 25, 2013, 2:51 AM EDT
your code is working well.....But m facing a problem when i am pressing "accept" button, it is updating the status "Y" in the table but on clicking the "not now" it also updating the table as "Y" inspite of "N". So please update the code for only update "button"
Gopal Ji Singh39 reputationPosted Jun 25, 2013, 3:57 AM EDT
thanks alot....your code is working well