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 LenkaPosted Jun 25, 2013, 6:52 AM
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
Gopal Ji SinghPosted Jun 25, 2013, 7:57 AM
thanks alot....your code is working well
Gopal Ji SinghPosted Jun 25, 2013, 6:51 AM
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"
Sunny SharmaPosted Jun 25, 2013, 6:45 AM
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 SinghPosted Jun 25, 2013, 6:30 AM
after your code m getting this error...please find the attachment
Gopal Ji SinghPosted Jun 25, 2013, 6:02 AM
Its a zip file...Please find the attachment.....name is Page
Iftikar HussainPosted Jun 25, 2013, 6:00 AM
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.
Sanjeeb LenkaPosted Jun 25, 2013, 5:44 AM
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
Gopal Ji SinghPosted Jun 25, 2013, 5:28 AM
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
Gopal Ji SinghPosted Jun 25, 2013, 5:27 AM
please find the attachment...
Iftikar HussainPosted Jun 25, 2013, 5:22 AM
I am not able to see any attachement.Can you please attach it
Regards,
Iftikar
Gopal Ji SinghPosted Jun 25, 2013, 5:14 AM
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 HussainPosted Jun 25, 2013, 5:02 AM
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 SinghPosted Jun 25, 2013, 4:22 AM
when m using lable1.text then m getting error like in attachment...
Iftikar HussainPosted Jun 25, 2013, 3:33 AM
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.
Sanjeeb LenkaPosted Jun 24, 2013, 12:13 PM
aspx page code and detail cs code.