Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Need Help !!! Bult Update with Dataset

Need Help !!! Bult Update with Dataset

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasehelpasp-netannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dinuraj
    wrote on last edited by
    #1

    Hi, I am developing a web appication using asp.net with c#. I am updating Dataset using datgrid EditItemTemplate and storing in cache. finally i want to update my table using SqlAdaptor Update mathod but i am gatting error.Please help me.. This is my Dataset Update mathod: public void grdEmployee_Update(Object o,DataGridCommandEventArgs e) { int id = (int)grdEmployee.DataKeys[e.Item.ItemIndex]; TextBox txtName,txtDesignation,txtSex,txtAge,txtSalary; txtName =(TextBox)e.Item.Cells[0].Controls[0]; txtDesignation =(TextBox)e.Item.Cells[1].Controls[0]; txtSex =(TextBox)e.Item.Cells[2].Controls[0]; txtAge =(TextBox)e.Item.Cells[3].Controls[0]; txtSalary =(TextBox)e.Item.Cells[4].Controls[0]; if (Cache["EMPCACHE"]!=null) { DataSet dsUpdate= (DataSet)Cache["EMPCACHE"]; dsUpdate.Tables[0].Rows[e.Item.ItemIndex]["NAME"]=txtName.Text; dsUpdate.Tables[0].Rows[e.Item.ItemIndex]["DESIGNATION"]=txtDesignation.Text; dsUpdate.Tables[0].Rows[e.Item.ItemIndex]["SEX"]=txtSex.Text; dsUpdate.Tables[0].Rows[e.Item.ItemIndex]["AGE"]=Convert.ToInt32(txtAge.Text); dsUpdate.Tables[0].Rows[e.Item.ItemIndex]["SALARY"]=Convert.ToSingle(txtSalary.Text); dsUpdate.AcceptChanges(); Cache["EMPCACHE"]=dsUpdate; grdEmployee.EditItemIndex = -1 ; grdEmployee.DataSource = dsUpdate; grdEmployee.DataBind(); }} Finally i am going to update on Database using this code private void btnDatabaseUpdate_Click(object sender, System.EventArgs e) { try { string strConnection= System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString"); SqlConnection con = new SqlConnection(); con.ConnectionString = strConnection; SqlDataAdapter sda = new SqlDataAdapter("select ID,NAME,DESIGNATION,SEX,AGE,SALARY from EMPLOYEEDETAILS",con); SqlCommandBuilder scb = new SqlCommandBuilder(sda); sda.Fill(dsObj,"EMPLOYEEDETAILS"); DataSet dsUpdate = (DataSet)Cache["EMPCACHE"]; dsObj = dsUpdate.Copy(); int success=sda.Update(dsObj,"EMPLOYEEDETAILS"); dsObj.AcceptChanges(); grdEmployee.DataSource = dsObj; grdEmployee.DataBind(); } catch (Exception ex) { Response.Write("
    " + ex.Message.ToString()); } } I am gatting this error: Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information. waiting for promp reply

    G 1 Reply Last reply
    0
    • D Dinuraj

      Hi, I am developing a web appication using asp.net with c#. I am updating Dataset using datgrid EditItemTemplate and storing in cache. finally i want to update my table using SqlAdaptor Update mathod but i am gatting error.Please help me.. This is my Dataset Update mathod: public void grdEmployee_Update(Object o,DataGridCommandEventArgs e) { int id = (int)grdEmployee.DataKeys[e.Item.ItemIndex]; TextBox txtName,txtDesignation,txtSex,txtAge,txtSalary; txtName =(TextBox)e.Item.Cells[0].Controls[0]; txtDesignation =(TextBox)e.Item.Cells[1].Controls[0]; txtSex =(TextBox)e.Item.Cells[2].Controls[0]; txtAge =(TextBox)e.Item.Cells[3].Controls[0]; txtSalary =(TextBox)e.Item.Cells[4].Controls[0]; if (Cache["EMPCACHE"]!=null) { DataSet dsUpdate= (DataSet)Cache["EMPCACHE"]; dsUpdate.Tables[0].Rows[e.Item.ItemIndex]["NAME"]=txtName.Text; dsUpdate.Tables[0].Rows[e.Item.ItemIndex]["DESIGNATION"]=txtDesignation.Text; dsUpdate.Tables[0].Rows[e.Item.ItemIndex]["SEX"]=txtSex.Text; dsUpdate.Tables[0].Rows[e.Item.ItemIndex]["AGE"]=Convert.ToInt32(txtAge.Text); dsUpdate.Tables[0].Rows[e.Item.ItemIndex]["SALARY"]=Convert.ToSingle(txtSalary.Text); dsUpdate.AcceptChanges(); Cache["EMPCACHE"]=dsUpdate; grdEmployee.EditItemIndex = -1 ; grdEmployee.DataSource = dsUpdate; grdEmployee.DataBind(); }} Finally i am going to update on Database using this code private void btnDatabaseUpdate_Click(object sender, System.EventArgs e) { try { string strConnection= System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString"); SqlConnection con = new SqlConnection(); con.ConnectionString = strConnection; SqlDataAdapter sda = new SqlDataAdapter("select ID,NAME,DESIGNATION,SEX,AGE,SALARY from EMPLOYEEDETAILS",con); SqlCommandBuilder scb = new SqlCommandBuilder(sda); sda.Fill(dsObj,"EMPLOYEEDETAILS"); DataSet dsUpdate = (DataSet)Cache["EMPCACHE"]; dsObj = dsUpdate.Copy(); int success=sda.Update(dsObj,"EMPLOYEEDETAILS"); dsObj.AcceptChanges(); grdEmployee.DataSource = dsObj; grdEmployee.DataBind(); } catch (Exception ex) { Response.Write("
      " + ex.Message.ToString()); } } I am gatting this error: Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information. waiting for promp reply

      G Offline
      G Offline
      Grapes R Fun
      wrote on last edited by
      #2

      Check your sqlDataSource object... first make sure the connection string you are using supports update operation. Second, when you get to the screen where it asks you to type in the SQL statements, click on the Advanced button, then check "Generate Insert, Update, and Delete statements" box. You may also check the "Optimistic concurrency" box as well. If the above doesn't help you, Zip your project, and email it to me so I can take a look at it :-) NightHawk13@hotmail.com

      Nila I do ANYTHING for a jumbo cup of coffee!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups