dataset update error

  • Thread starter Thread starter Marina
  • Start date Start date
Calling AcceptChanges before doing an update, sets all the rows to
'unmodified'. So any changes/additions/deletions are lost - nothing to
update.

I'm also not following why you are re-retrieving the data, merging it, then
trying to update. Why not just update what was passed to you?
 
hi i am trying to update a dataset in my client windows applicaton
and then pass that dataset to the web service so that it can update the
database..
i have operations like update, delete and insert.
im trying insert in teh following code and it doesnt work.
what am i doing wrong?



private void cmdSubmit_Click(object sender, System.EventArgs e)
{
DataRow dr = dsCity.Tables["city"].NewRow();
dr["cityname"]="newyork";
MessageBox.Show(dsCity.Tables["city"].Rows.Count.ToString()); //gives 2
dsCity.Tables["city"].Rows.Add(dr);
MessageBox.Show(dsCity.Tables["city"].Rows.Count.ToString()); //gives 3.
ser=new Service1();
ser.updateCity(dsCity);
}




[WebMethod]
public DataSet updateCity(DataSet ds)
{
SqlCommandBuilder cmdBuilder = new SqlCommandBuilder (daCity);
daCity.Update(ds.Tables["city"]);
return dsCity;
}


error
Object reference not set to an instance of an object.
at CarRentalWS.Service1.updateCity(DataSet ds) in ...


thanx
 
hi
well actually is like this..


web service

[WebMethod]
public DataSet getAllCities()
{
SqlDataAdapter daCity ;
DataSet dsCity;

string sqlQuery = "select * from City";
daCity=new SqlDataAdapter(sqlQuery,conn);
dsCity= new DataSet();
daCity.Fill(dsCity,"City");
return dsCity;
}

[WebMethod]
public void updateCity(DataSet ds)
{
string sqlQuery = "select * from City";
SqlDataAdapter daCity=new SqlDataAdapter(sqlQuery,conn);
SqlCommandBuilder cmdBuilder = new SqlCommandBuilder (daCity);
DataSet dsCity= new DataSet();
daCity.Fill(dsCity,"City");
dsCity.Merge(ds);
dsCity.Tables["City"].AcceptChanges();
daCity.Update(dsCity); //i get an error here.
}



-------------------------------
Win application the client

private DataSet dsCity; //global

private void Form1_Load(object sender, System.EventArgs e)
{
//fill the city combo
ser=new Service1();
dsCity=ser.getAllCities();
cmbPickCity.Items.Clear();
foreach (DataRow dr in dsCity.Tables["City"].Rows)
{
if(!dr.IsNull(0))
cmbPickCity.Items.Add(dr["CityName"]);
}
cmbPickCity.SelectedIndex=0;
}



private void cmdSubmit_Click(object sender, System.EventArgs e)
{
DataRow dr = dsCity.Tables["city"].NewRow();
dr["cityid"]=3;
dr["cityname"]="AS";
MessageBox.Show(dsCity.Tables["city"].Rows.Count.ToString());
dsCity.Tables["city"].Rows.Add(dr);
MessageBox.Show(dsCity.Tables["city"].Rows.Count.ToString() + " state=" +
dsCity.Tables["City"].Rows[2].RowState.ToString());
ser=new Service1();
ser.updateCity(dsCity);
}



---------
and it gives me this error
System.InvalidOperationException: Update unable to find
TableMapping['Table'] or DataTable 'Table'.
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable)


why doesnt it update the database.
thanx for your help
 
thats what i actually wanted to do ..

i just want to pass a dataset to my webservice and update it to my database.
but i read somewhere that i should merge my dataset ..but i guess i got that
wrong
and misunderstood it.
all i want to do is when my webservice receives a dataset i want to update
all the
changes to the database.

i tried just updating what is being passed to me as in

[WebMethod]
public void updateCity(DataSet ds)
{
daCity.Update(ds); //dacity is declared global
}
but i should nt use a global var becos its not going to store state anyway.
so im not quite sure how to do it.
thanx
 
Back
Top