|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataAdapter doesn't insert recordI am using VS2005, .NET 2, SQL Server Express 2005. I have no trouble reading records, but the updates to not get persisted to the database. Why won't this code insert a new record in the EventLog table? Any help would be great! CondoTrackerDatabaseDataSet.EventLogDataTable table = this.EventLogTableAdapter.GetData(); //Rows = 1 MessageBox.Show(table.Rows.Count.ToString()); CondoTrackerDatabaseDataSet.EventLogRow logRow = table.NewEventLogRow(); logRow.EventDate = DateTime.Now; logRow.RoomNumber = roomNumber; logRow.EventTypeLabel = eventType.ToString(); logRow.LogText = logText; //Add Row table.AddEventLogRow(logRow); //Rows = 2 MessageBox.Show(table.Rows.Count.ToString()); //Supposedly commits to database this.EventLogTableAdapter.Update(table); //Refill table this.EventLogTableAdapter.ClearBeforeFill = true; this.EventLogTableAdapter.Fill(table); //Rows = 1 MessageBox.Show(table.Rows.Count.ToString()); From the looks of your code, calling HasChanges right before the Update
should return true (just double check it to be sure). The problem is most likely in your insert statement, double check the code you have for it and make sure everything looks right - if that doesn't turn up anything, check with Sql Profiler and see if anything is being sent back tot he db and if so, what that is. Show quote "Jed" <jedatu@newsgroups.nospam> wrote in message news:F7909A72-4A95-49E1-A488-2B588FEA9E4A@microsoft.com... > This has got to be dumb question, but I cannot figure it out. > > I am using VS2005, .NET 2, SQL Server Express 2005. I have no trouble > reading records, but the updates to not get persisted to the database. > > Why won't this code insert a new record in the EventLog table? Any help > would be great! > > CondoTrackerDatabaseDataSet.EventLogDataTable table = > this.EventLogTableAdapter.GetData(); > //Rows = 1 > MessageBox.Show(table.Rows.Count.ToString()); > CondoTrackerDatabaseDataSet.EventLogRow logRow = table.NewEventLogRow(); > logRow.EventDate = DateTime.Now; > logRow.RoomNumber = roomNumber; > logRow.EventTypeLabel = eventType.ToString(); > logRow.LogText = logText; > //Add Row > table.AddEventLogRow(logRow); > //Rows = 2 > MessageBox.Show(table.Rows.Count.ToString()); > //Supposedly commits to database > this.EventLogTableAdapter.Update(table); > //Refill table > this.EventLogTableAdapter.ClearBeforeFill = true; > this.EventLogTableAdapter.Fill(table); > //Rows = 1 > MessageBox.Show(table.Rows.Count.ToString()); Thanks for the reply.
Well, the only HasChanges method I see is on the DataSet. However, table.DataSet == null. Should the DataSet property be populated as a result of GetData()? Show quote "W.G. Ryan - MVP" wrote: > From the looks of your code, calling HasChanges right before the Update > should return true (just double check it to be sure). The problem is most > likely in your insert statement, double check the code you have for it and > make sure everything looks right - if that doesn't turn up anything, check > with Sql Profiler and see if anything is being sent back tot he db and if > so, what that is. > "Jed" <jedatu@newsgroups.nospam> wrote in message > news:F7909A72-4A95-49E1-A488-2B588FEA9E4A@microsoft.com... > > This has got to be dumb question, but I cannot figure it out. > > > > I am using VS2005, .NET 2, SQL Server Express 2005. I have no trouble > > reading records, but the updates to not get persisted to the database. > > > > Why won't this code insert a new record in the EventLog table? Any help > > would be great! > > > > CondoTrackerDatabaseDataSet.EventLogDataTable table = > > this.EventLogTableAdapter.GetData(); > > //Rows = 1 > > MessageBox.Show(table.Rows.Count.ToString()); > > CondoTrackerDatabaseDataSet.EventLogRow logRow = table.NewEventLogRow(); > > logRow.EventDate = DateTime.Now; > > logRow.RoomNumber = roomNumber; > > logRow.EventTypeLabel = eventType.ToString(); > > logRow.LogText = logText; > > //Add Row > > table.AddEventLogRow(logRow); > > //Rows = 2 > > MessageBox.Show(table.Rows.Count.ToString()); > > //Supposedly commits to database > > this.EventLogTableAdapter.Update(table); > > //Refill table > > this.EventLogTableAdapter.ClearBeforeFill = true; > > this.EventLogTableAdapter.Fill(table); > > //Rows = 1 > > MessageBox.Show(table.Rows.Count.ToString()); > > > Jed - DataSet is the object with HasChanges but if you have a DataTable that
wasn't added to a dataset, tehn it will be null. I don't think this is the problem though - b/c I think the changes are there, I mentioned it mainly for the sake of being thorough. Show quote "Jed" <jedatu@newsgroups.nospam> wrote in message news:06342FEB-578D-41D2-82CA-B32B4DB4A3F5@microsoft.com... > Thanks for the reply. > > Well, the only HasChanges method I see is on the DataSet. However, > table.DataSet == null. Should the DataSet property be populated as a > result > of GetData()? > > "W.G. Ryan - MVP" wrote: > >> From the looks of your code, calling HasChanges right before the Update >> should return true (just double check it to be sure). The problem is >> most >> likely in your insert statement, double check the code you have for it >> and >> make sure everything looks right - if that doesn't turn up anything, >> check >> with Sql Profiler and see if anything is being sent back tot he db and if >> so, what that is. >> "Jed" <jedatu@newsgroups.nospam> wrote in message >> news:F7909A72-4A95-49E1-A488-2B588FEA9E4A@microsoft.com... >> > This has got to be dumb question, but I cannot figure it out. >> > >> > I am using VS2005, .NET 2, SQL Server Express 2005. I have no trouble >> > reading records, but the updates to not get persisted to the database. >> > >> > Why won't this code insert a new record in the EventLog table? Any >> > help >> > would be great! >> > >> > CondoTrackerDatabaseDataSet.EventLogDataTable table = >> > this.EventLogTableAdapter.GetData(); >> > //Rows = 1 >> > MessageBox.Show(table.Rows.Count.ToString()); >> > CondoTrackerDatabaseDataSet.EventLogRow logRow = >> > table.NewEventLogRow(); >> > logRow.EventDate = DateTime.Now; >> > logRow.RoomNumber = roomNumber; >> > logRow.EventTypeLabel = eventType.ToString(); >> > logRow.LogText = logText; >> > //Add Row >> > table.AddEventLogRow(logRow); >> > //Rows = 2 >> > MessageBox.Show(table.Rows.Count.ToString()); >> > //Supposedly commits to database >> > this.EventLogTableAdapter.Update(table); >> > //Refill table >> > this.EventLogTableAdapter.ClearBeforeFill = true; >> > this.EventLogTableAdapter.Fill(table); >> > //Rows = 1 >> > MessageBox.Show(table.Rows.Count.ToString()); >> >> >> |
|||||||||||||||||||||||