ASP.NET - Urgent
Asked By saranya
03-Feb-12 02:54 AM

Hi frndz
iam doing project in asp.net 2.0,c#. In my project i have to add,update delete the products in admin page. when i add the product it works gud. but when i update the products and give submit the product names didnt get update . plz help very urgent.
My fields in database are:
1.id
2.reference
3.manufacturer
4.model
5.year
6.colors
7.format
8.description
9.photo
10.photo1
Below is my code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Admin_edit_stock : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
int pID;
connection con = new connection();
protected void Page_Load(object sender, EventArgs e)
{
if (Session["admin"] == null)
{
Response.Redirect("default.aspx");
}
String cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
String callbackScript;
callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + ";}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
GridView1load();
}
public String GetCallbackResult()
{
return "";
}
public void RaiseCallbackEvent(String eventArgument)
{
string ID = eventArgument.ToString();
pID = Convert.ToInt32(ID);
delete();
}
protected void gridviewchanged(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
public void GridView1load()
{
SqlDataAdapter da = new SqlDataAdapter("select id,reference,manufacturer,model,year,colors,format,description,photo,photo1 from tbl_saffire", con.sqlconnection());
DataSet ds = new DataSet();
da.Fill(ds, "tbl_saffire");
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void delete()
{
SqlCommand cmd = new SqlCommand("delete from tbl_saffire where id='" + pID + "'", con.sqlconnection());
cmd.ExecuteReader();
GridView1load();
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd2 = new SqlCommand("select max(id) id from tbl_saffire", con.sqlconnection());
SqlDataReader dr = cmd2.ExecuteReader();
if (dr.Read())
{
lbl_id.Text = dr.GetValue(0).ToString();
}
if (FileUpload2.FileName == "")
{
lbl_path.Text = "unknown.jpg";
}
else
{
lbl_path.Text = lbl_maxid.Text + FileUpload2.FileName;
FileUpload2.PostedFile.SaveAs(Server.MapPath("~/Admin/upload/") + lbl_path.Text);
}
if (FileUpload1.FileName == "")
{
lbl_path1.Text = "unknown.jpg";
}
else
{
lbl_path1.Text = lbl_maxid.Text + FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Admin/upload/") + lbl_path1.Text);
}
SqlCommand cmd = new SqlCommand("update tbl_saffire set reference='"
+ Txt_mnfrs.Text + "',manufacturer='"
+ Txt_model.Text + "',model='"
+ Txt_year.Text + "',year='"
+ Txt_color.Text + "',colors='"
+ Txt_size.Text + "',format='"
+ txt_desc.Text + "',description='"
+ lbl_path.Text + "',photo='"
+ lbl_path1.Text + "'where id='" + lbl_id.Text + "'", con.sqlconnection());
cmd.ExecuteNonQuery();
Response.Redirect("edit_stock.aspx");
lbl_msg.Text = "Record Updated Sucessfully!";
txt_ref.Text = "";
Txt_mnfrs.Text = "";
Txt_model.Text = "";
Txt_year.Text = "";
Txt_color.Text = "";
Txt_size.Text = "";
txt_desc.Text = "";
lbl_path.Text = "";
lbl_path1.Text = "";
}
protected void update(object sender, EventArgs e)
{
LinkButton lik = (LinkButton)sender;
GridViewRow di = (GridViewRow)lik.Parent.Parent;
HiddenField hidden = (HiddenField)di.FindControl("hidden");
lbl_id.Text = hidden.Value;
SqlCommand cmd1 = new SqlCommand("select id,reference,manufacturer,model,year,colors,format,description,photo,photo1 from tbl_saffire where id='" + lbl_id.Text + "'", con.sqlconnection());
SqlDataReader dr = cmd1.ExecuteReader();
if (dr.Read())
{
lbl_id.Text = dr.GetValue(0).ToString();
txt_ref.Text = dr.GetValue(1).ToString();
Txt_mnfrs.Text = dr.GetValue(2).ToString();
Txt_model.Text = dr.GetValue(3).ToString();
Txt_year.Text = dr.GetValue(4).ToString();
Txt_color.Text = dr.GetValue(5).ToString();
Txt_size.Text = dr.GetValue(6).ToString();
txt_desc.Text = dr.GetValue(7).ToString();
lbl_path.Text = dr.GetValue(8).ToString();
lbl_path1.Text = dr.GetValue(9).ToString();
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
Help me frndz its very urgent!
Danasegarane Arunachalam replied to saranya
Where do you call the below method.
protected void update(object sender, EventArgs e)
I am not seeing it anywhere ?
And also in the same method I can see that you are only fetching the record and not updating anything ?
SqlCommand cmd1 = new SqlCommand("select
id,reference,manufacturer,model,year,colors,format,description,photo,photo1
from tbl_saffire where id='" + lbl_id.Text + "'", con.sqlconnection());
SqlDataReader dr = cmd1.ExecuteReader();
if (dr.Read())
{
lbl_id.Text = dr.GetValue(0).ToString();
txt_ref.Text = dr.GetValue(1).ToString();
Txt_mnfrs.Text = dr.GetValue(2).ToString();
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup message", "setconformation();setScrollerWidth();slidStart();", true); if (CadPartListpopUp ! = null) { / / ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "cadpop", "document.getElementById('" + CadPartListpopUp.ClientID + "').style.display = '';ShowBackShadow('dvbackShadow', true);", true); } } catch (ExceptionHandler ex) { ErrorHandler.SetMessage(ex.MessageDetails(), spnmessage); / / ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "popup message", "document.getElementById('" + ErrorPop.ClientID + "').style.display = '';", true); ScriptManager RegisterClientScriptBlock(this, this.GetType(), "popup message", "Message_MoveTO_popup('" + spnmessage.ClientID + "', 'spnmessage');JqueryPopupShow();", true); } catch (Exception ex) { objHandlers = new ExceptionHandler(ex, true); ErrorHandler.SetMessage(objHandlers.MessageDetails(), spnmessage); / / ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "popup message", "document.getElementById('" + ErrorPop.ClientID + "').style.display = '';", true); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "popup message", "Message_MoveTO_popup('" + spnmessage.ClientID + "', 'spnmessage');JqueryPopupShow();", true); } } private void BindActor() { / / ddlCustomer name = "sender"> < / param> / / / <param name = "e"> < / param> protected void imgbtnAddCadPro_OnClick(object sender, ImageClickEventArgs e) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "cadpop", "document.getElementById('" + CadProdListpopUp.ClientID + "').style.display = '';ShowBackShadow('dvbackShadow', true);", true); Chk_Product_Amada_CadCAM_Service GetProduct_Webservice(); } catch (Exception ex) { / / ErrorHandler.SetMessage(MessageHandler.AppMessage("127"), spnmessage); spnmessage.Text = ex.Message; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "popup message", "Message_MoveTO_popup('" + spnmessage.ClientID + "', 'spnmessage');JqueryPopupShow();", true); } if (obj ! = null) { List _Prod_name); } catch (Exception ex) { / / ErrorHandler.SetMessage(MessageHandler.AppMessage("127"), spnmessage); spnmessage.Text = ex.Message; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "popup message", "Message_MoveTO_popup('" + spnmessage.ClientID + "', 'spnmessage');JqueryPopupShow();", true); } / * Get Part Details From
SqlConnection = new SqlConnection([Your Connections String]) dim ds as new DataSet dim daTable1 as new SqlDataAdapter dim daTable2 as new SqlDataAdapter dim daTable3 as new SqlDataAdapter dim daTable4 as new SqlDataAdapter daTable1.SelectCommand = "select * from table1 where . . ." daTable2.SelectCommand = "select * from table2 where . . ." daTable3.SelectCommand = "select attempting to recreate what you mentioned however, I cannot find any means of producing a SqlDataAdapter in VS2005. I appear to only have the option to create SqlDataSources. What hapened to post_date, author, comments, ct_number FROM Comments WHERE ct_number = ctpt.ct_number"; SqlConnection conn = new SqlConnection(strConn); SqlDataAdapter da = new SqlDataAdapter(strSql, conn); da.TableMappings.Add("Customers1", "Customers"); da.TableMappings.Add("Customers2", "CTPT"); da.TableMappings.Add post_date, author, comments, ct_number FROM Comments WHERE ct_number = ctpt.ct_number"; SqlConnection conn = new SqlConnection(conn); SqlDataAdapter da = new SqlDataAdapter(strSql, conn); da.TableMappings.Add("Customers1", "Customers"); da.TableMappings.Add("Customers2", "CTPT
to get the problems. Is there any good way to update multiple tables by using SqlDataAdapter.Update()? Thank you / * New Rows in ParentTable and ChildTable * * - -- -- -ParentTable- -- -- - * ID Animal * 1 Cat * * * - -- -- -ChildTable first way I use is to follow the update sequence recommended by book: adapter1 = new SqlDataAdapter("Select * from ChildTable", con); SqlDataAdapter adapter2 = new SqlDataAdapter("Select * from ParentTable", con); SqlCommandBuilder sb = new SqlCommandBuilder(adapter1); SqlCommandBuilder sb1 = new SqlCommandBuilder(adapter2); adapter1 NewDataSet.Tables["ChildTable"].Select(null, null, DataViewRowState.Added)); - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- The 2nd way is to use 2 SqlDataAdapter seperately to update tables, but still get the same problem : The Child table row "3 small cat 1" is wrong adapter1 = new SqlDataAdapter("Select * from ChildTable", con); SqlDataAdapter adapter2 = new SqlDataAdapter("Select * from ParentTable", con); SqlCommandBuilder sb = new SqlCommandBuilder(adapter1); SqlCommandBuilder sb1 = new SqlCommandBuilder(adapter2); adapter1
about populating listboxes. very good. Can u tell me how I can clean the below? SqlDataAdapter title; DataSet ds1; title = new SqlDataAdapter ("Select * FROM titles ", m_strConnection); ds1 = new DataSet(); title.Fill (ds1, "Table"); lbTitle.DataSource = ds1.Tables Columns["title_name"].ColumnName.ToString(); lbTitle.DataValueField = ds1.Tables[0].Columns["title_id"].ColumnName.ToString(); lbTitle.DataBind () ; SqlDataAdapter gender; DataSet ds2; gender = new SqlDataAdapter ("Select * FROM genders ", m_strConnection); ds2 = new DataSet(); gender.Fill (ds2, "Table"); lbGender.DataSource = ds2.Tables Columns["gender_name"].ColumnName.ToString(); lbGender.DataValueField = ds2.Tables[0].Columns["gender_id"].ColumnName.ToString(); lbGender.DataBind () ; SqlDataAdapter secretwordtype; DataSet ds3; secretwordtype = new SqlDataAdapter ("Select * FROM secretwordtypes ", m_strConnection); ds3 = new DataSet(); secretwordtype.Fill (ds3, "Table"); lbSecretWordType.DataSource = ds3.Tables Columns["secretwordtype_name"].ColumnName.ToString(); lbSecretWordType.DataValueField = ds3.Tables[0].Columns["secretwordtype_id"].ColumnName.ToString(); lbSecretWordType.DataBind (); SqlDataAdapter state; DataSet ds4; state = new SqlDataAdapter ("Select * FROM states ", m_strConnection); ds4 = new DataSet(); state.Fill (ds4, "Table"); lbStateProvince.DataSource = ds4.Tables