473,378 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

C# Datatable won't update Database

Hi, I need serious help with a C# winform, I have a dataset with several tables, and I have structured a 3-tier code architecture. My problem is that updates to the database dont work, even though its coded as follows:

Expand|Select|Wrap|Line Numbers
  1. public bool AddVideo(int codenumber, string title)
  2.             //create new VideoRow
  3.             Video.VideosDataTable videosTable = new Video.VideosDataTable();
  4.             Adapter.Fill(videosTable);
  5.             Video.VideosRow videoRow = videosTable.NewVideosRow();
  6.  
  7.             videoRow.CodeNumber = codenumber;
  8.             videoRow.Title = title;
  9.  
  10.             //add the new video
  11.             videosTable.AddVideosRow(videoRow);
  12.             int rowsAffected = Adapter.Update(videosTable);            //return True if row inserted, False if not
  13.             return rowsAffected == 1;
  14. }
Weird thing it shows the data fine on the datagrid each time I press the "addButton", but does not save any changes in the database... once I close the debugger and restart no data has been saved. Anyone know how to fix this?

form.cs looks like this:

Expand|Select|Wrap|Line Numbers
  1. private void addButton_Click(object sender, EventArgs e)
  2.         {
  3.             VideosBLL videoLogic = new VideosBLL();
  4.             try
  5.             {
  6.                 videoLogic.AddVideo(Int32.Parse(codeBox.Text), titleBox.Text);
  7.             }
  8.             catch (Exception ex)
  9.             {
  10.                 MessageBox.Show(ex.Message,"Error"
  11.                 ,MessageBoxButtons.OK,MessageBoxIcon.Error);
  12.             }
  13.             dataGridView1.DataSource = videoLogic.GetVideos();
  14.         }
Nov 29 '07 #1
1 1527
Shashi Sadasivan
1,435 Expert 1GB
Have you checked the Updatecommand being generated?

you might want to regenerate the update command if you are using xsd files
Nov 29 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: randy | last post by:
Hello all, I have a DataTable which I am building column by column and adding rows after each new column. The DataTable columns match the columns in my database table. I'm building the...
1
by: jason | last post by:
Hello everyone, I have some general questions about the DataTable object, and how it works. Moderately new to C#, I have plenty of texts describing the language, but not so much to reference...
12
by: Art | last post by:
Hi, I need help -- again -- I have a DataGrid with a DataTable as its source. It displays wonderfully when I put in some test data (withinin the code). Now, I'd like to change one of the...
11
by: Geoff | last post by:
Hi I have a DataTable with thousands of rows. I want a quick way to insert the rows into a table in an Access database with the same structure. I have been using an update command but found it...
1
by: Tim Kelley | last post by:
I need to loop through a datatable and update a particular field. This seems like it should be fairly easy but it is giving me fits. Here is the code that I have so far. foreach (DataRow row...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
7
by: Wayne Gibson | last post by:
Hi All, Was wondering if anybody could help. I'm currently trying to copy a record from datatable to another. I have two problems: 1) Transferring the record from one datatable to another. 2)...
1
by: gomathinayagam | last post by:
hai, am only beginer in c#... i am trying to connect database with webform. using a technique that the fields of the table and the controls in a form are named same...then i try get the controls...
5
by: jehugaleahsa | last post by:
Hello: What is the point of using a DataTable in ASP .NET? We are unsure how you can use them without 1) rebuilding them every postback, or 2) taking up precious memory. We are not sure how to...
9
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got a routine that builds a table using different queries, different SQL Tables, and adding custom fields. It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the table...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.