Hi guys,
I'm using a very simple database and dataset and it appears to be working, except I can't actually save any data. Here's what I did:
I created an empty database with a corresponding empty dataset. I filled it in with 4 rows of dummy data (ID, name, address, etc). I dragged the table (called Lawyer) to the dataset. This created the update and insert methods.
I then created a class, which has two methods. One to count the records, and one to add new data. This should be simple, and I've done it before, but for some reason this compiles and runs perfectly fine, but it doesn't actually commit anything to either the dataset or database. I've got this class working with a GUI, and the GUI allows me to add rows, and shows me how many rows are in the table. I'm able to add rows and see the number of rows go up. However, once I quit the application and check the dataset and database, there are no new records.
Here is my class. Can anyone give me any hints as to why this may not be saving changes to the dataset and database?
Thanks!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.OleDb;
namespace UserManagement
{
class AddLawyerHandler
{
DAL.LawyerDataSet dsLaw = new DAL.LawyerDataSet();
DAL.LawyerDataSetTableAdapters.LawyerTableAdapter lawyerList = new DAL.LawyerDataSetTableAdapters.LawyerTableAdapter();
DAL.LawyerDataSet.LawyerDataTable LawyerTable = new DAL.LawyerDataSet.LawyerDataTable();
static SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Lawyer.mdf;Integrated Security=True");
public int FindLawyerNumbers()
{
int count = lawyerList.Fill(LawyerTable);
return count;
}
public void AddLawyer()
{
int lawyerID = FindLawyerNumbers() + 1;
LawyerTable.AddLawyerRow(lawyerID, "Johnno Matthews", "Matthews & Co", "16 Tynes St, Tyne", "06525844", "john@jm.com", "www.jm.com");
lawyerList.Update(LawyerTable);
dsLaw.AcceptChanges();
lawyerID = 0;
}
}
}