Click here to Skip to main content
15,887,344 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 :

C#
 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.
HTML
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)



HTML
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
Updated 25-Aug-12 23:34pm
v2

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
 
Share this answer
 
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[^]
 
Share this answer
 
You can use this

For reading data we use state table and function is
C#
//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.
C#
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
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900