Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hello freinds,
I am using a dataset page dataset.xsd. In it i am having a table named asp3, Whenever i am trying to insert the data in the table through DataSet1TableAdapters.asp31TableAdapter class, data is inserted but if i am trying to update or delete the data it is giving an error. My code is :
 
 protected void insrt_btn_Click(object sender, EventArgs e)
        {
            int emp_id = int.Parse(id_txtbx.Text);
            int sal = int.Parse(sal_txtbx.Text);
            DataSet1TableAdapters.asp31TableAdapter da3 = new DataSet1TableAdapters.asp31TableAdapter();
            da3.Insert(emp_id, name_txtbx.Text, sal);
            GridView2.DataSource = da3.GetData();
            GridView2.DataBind();
        }
 
        protected void updt_btn_Click(object sender, EventArgs e)
        {
            int emp_id = int.Parse(id_txtbx.Text);
            int sal = int.Parse(sal_txtbx.Text);
            DataSet1TableAdapters.asp31TableAdapter da3 = new DataSet1TableAdapters.asp31TableAdapter();
            da3.Update(emp_id, name_txtbx.Text, sal);
            GridView2.DataSource = da3.GetData();
            GridView2.DataBind();
        }
 
        protected void dlt_btn_Click(object sender, EventArgs e)
        {
            int emp_id = int.Parse(id_txtbx.Text);
            int sal = int.Parse(sal_txtbx.Text);
            DataSet1TableAdapters.asp31TableAdapter da3 = new DataSet1TableAdapters.asp31TableAdapter();
            da3.Delete(emp_id);
            GridView2.DataSource = da3.GetData();
            GridView2.DataBind();
        }
    }
}
 
The bold lines are giving error.
Error	2	'DAL_BLL.DataSet1TableAdapters.asp31TableAdapter' does not contain a definition for 'Delete' and no extension method 'Delete' accepting a first argument of type 'DAL_BLL.DataSet1TableAdapters.asp31TableAdapter' could be found (are you missing a using directive or an assembly reference?)	C:\Users\KANHA\Documents\Visual Studio 2010\Projects\DAL BLL\DAL BLL\WebForm1.aspx.cs	63	17	DAL BLL (dataset)
 

Error	1	No overload for method 'Update' takes 3 arguments	C:\Users\KANHA\Documents\Visual Studio 2010\Projects\DAL BLL\DAL BLL\WebForm1.aspx.cs	53	13	DAL BLL (dataset)
 

Thanx in advance
 
With regards,
Rakesh Sharma
Posted 25-Aug-12 22:47pm
Edited 25-Aug-12 23:34pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi ,
Check your asp31TableAdapter if it has UpdateCommand and DeleteCommand match to your need and try to execute them Query from the Designer to make sure it works fine then rebuild your application
Best Regards
M.Mitwalli
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

to update and delete using table adapters you need to set update command and delete command for tableadapter
 
Refer following URL to set update command and delete command
1[^]
 
http://msdn.microsoft.com/en-us/library/ms171933%28v=vs.80%29.aspx[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You can use this
 
For reading data we use state table and function is
//for read data 
 public void readstate()
        {
            //Insert
            dataAdState.SelectCommand = new SqlCommand("select * from state_master", con);
           
            dataAdState.InsertCommand = new SqlCommand("insert into state_master(state_id,state_name) values(@state_id,@state_name)", con);
            dataAdState.InsertCommand.Parameters.Add("@state_name", SqlDbType.Text).SourceColumn="state_name";
            dataAdState.InsertCommand.Parameters.Add("@state_id", SqlDbType.Int).SourceColumn = "state_id";
            //Update
            dataAdState.UpdateCommand = new SqlCommand("update state_master set state_name=@state_name where state_id=@state_id",con);
            dataAdState.UpdateCommand.Parameters.Add("@state_name", SqlDbType.Text).SourceColumn = "state_name";
            dataAdState.UpdateCommand.Parameters.Add("@state_id", SqlDbType.Int).SourceColumn = "state_id";
//Delete
            dataAd.DeleteCommand = new SqlCommand("delete from state_master where state_id=@state_id");
            dataAdState.DeleteCommand.Parameters.Add("@state_id", SqlDbType.Int).SourceColumn = "state_id";
            dataAdState.Fill(dataset, "State");
            dataset.Tables["State"].PrimaryKey = new DataColumn[] { dataset.Tables["State"].Columns["state_id"] };
        }
And this for update data.
 public void updateState(int state_id, string name)
        {
 
            dataset.Tables["State"].PrimaryKey = new DataColumn[] { dataset.Tables["State"].Columns["state_id"] };
            
            DataRow row = dataset.Tables["State"].Rows.Find(state_id);
           
            row["state_name"] = name;
         
            DataTable d = dataset.Tables["State"].GetChanges(DataRowState.Modified);
            dataAdState.Update(d);
        }
 
same for delete
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 675
1 CPallini 320
2 Sergey Alexandrovich Kryukov 305
3 BillWoodruff 285
4 Peter Leow 255


Advertise | Privacy | Mobile
Web03 | 2.8.141029.1 | Last Updated 26 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100