posted on Monday, March 01, 2004 3:27 PM
by
warstar
N00B DataAdapter Mistake
So I wanted to insert some info into a table and I was using:
sqlDataAdapterCategoryList.InsertCommand.Parameters["Titel"].Value = txt_titel;
sqlDataAdapterCategoryList.InsertCommand.Parameters["Description"].Value = txt_description;
sqlDataAdapterCategoryList.InsertCommand.ExecuteNonQuery();
And this worked perfect but when I wanted to get the info from the select that is included into the generated insert statement. So after trying to fill the dataset after the insert command execution I could get the entire last put in using:
ds.Categories[(ds.Categories.Count-1)]
Where ds is the dataset. But this seemed to be a wasted of data traffic so I needed something better so after trying some stuff for 30 min I went to my neighbor and hey showed me this:
DataSetCategory ds = new DataSetCategory();
Category db = new Category();
ds.Categories.AddCategoriesRow(Int32.Parse(ddl_parent.SelectedValue),txt_titel.Text,txt_description.Text);
sqlDataAdapterCategoryList.Update(ds);
So now I could insert the information and get the information using:
ds.Categories[0]
Without wasting resources or using a datareader or scalar