Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 DataAdapter.Update just aint Updating...

Author  Topic 

asderex
Starting Member

10 Posts

Posted - 2007-11-18 : 20:36:03
Hi All,

I have a very simple typed dataset containing a datatable. The initial query in the table adapter was a simple Select * from SellOrders with a couple of more specific queries added and used below. I have stuck with the Update/Insert commands generated automatically with my intitial Select statement.

My Code is as follows:

Sub Something()

Dim SellOrdersAdapter As New ShareTraderTableAdapters.SellOrderTableAdapter
Dim NMsellorders, MarketSellOrders As ShareTrader.SellOrderDataTable

NMsellorders = SellOrdersAdapter.GetNonMktSellDataByPrice(12)
MarketSellOrders = SellOrdersAdapter.GetMktSellByPrice()

Dim sellOrderRow As ShareTrader.SellOrderRow

For Each sellOrderRow In NMsellorders
sellOrderRow.AtMarket = True
Next

NMsellorders.AcceptChanges()
SellOrdersAdapter.Update(NMsellorders)

End Sub

I am simply trying to get the changes I have made to the datatable (i.e. set the AtMarket bit column to true). The code runs with no errors thrown but when I check in SQL Serv Management Studio no changes have occured in the SellOrder Table. I thought this was handled by the dataadapter when the Update Method was called. Any suggestions would be most welcome.

Asderex

srimathi.mani
Starting Member

3 Posts

Posted - 2007-11-28 : 05:41:12
Hey,

I have pasted a sample code in C# which inserts a new record into the databse using a dataset.See if this helps u out

SqlConnection dbConnection = new SqlConnection("User ID=dd;Password=aa;Database=northwind;Server=ent;");
string strSelectSql = "Select * from SellOrders";

//Open the connection
dbConnection.Open();

//Create a command
SqlCommand selectSqlCommand = new SqlCommand(strSelectSql, dbConnection);

SqlDataAdapter Dataadapter = new SqlDataAdapter(selectSqlCommand);

DataSet dataset = new DataSet();
Dataadapter.Fill(dataset);

DataRow row1;
row1 = dataset.Tables[0].NewRow();

row1["Code"] = "Newcodefffff";
row1["Description"] = "NewDescription";

dataset.Tables[0].Rows.Add(row1);

SqlCommandBuilder com = new SqlCommandBuilder(Dataadapter);
Dataadapter.Update(dataset);
Go to Top of Page

asderex
Starting Member

10 Posts

Posted - 2007-11-28 : 15:12:00
Hi,

Thanks for the suggestion. I figured out my problem. Because I was calling the NMsellorders.AcceptChanges() method, when the SellOrdersAdapter.Update(NMsellorders) method was called it was not seeing any changes in NMSellOrders to make. i.e. acceptChanges() makes the dataset think there have been no changes (although the values are different). By removing AcceptChanges the changes are propagated to the DB.

Thanks

Campbell
Go to Top of Page
   

- Advertisement -