In my project I have one DataSet ('Step') from this I have two tables ('Students' and 'PostCode'). I have set them up in both the same way. I can successfully call Step.Students.FindBy(PK) and the function will return either null or not null depending on the results it finds, which is what it should do. However my second table I call Step.PostCode.FindBy(PK) and it always returns null no matter what is in the database. It actually returns null for everything, select, count etc. It looks to me like the dataset isn't actually connecting, even though my GridView successfully shows the content of the table I originally thought the changes weren't being committed but even when I use AcceptChanges() it still doesn't work.
One thought I have had though is that I am still accessing the first table when trying to access the second.
Any thoughts anyone has on this would be great, i have tried looking for an answer for 2 days without any success.
Thanks
Daniel
----------------------------------------------------------------------------------------------
class ExcelHandling
{
public void getData(string Location, StepDataSet Step)
{
// Create connection to the JET Datasource
string dummy = "";
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" + Location + @";
Extended Properties=""Excel 8.0;HDR=YES;""";
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
int count = 0;
using (DbConnection connection = factory.CreateConnection())
{
connection.ConnectionString = connectionString;
using (DbCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT ApplicationID, StudentID, AppEligibleCurrentYear, AppForename, AppSurname, AppAddress1, AppAddress2, AppAddress3, AppCity, Email, Phone, AppPostCode, AppTermAddress1, AppTermAddress2, AppTermAddress3, AppTermCity, AppTermPostCode, AppDOB, AppUniversityName, AppUniversityNameNotListed, AppCourseName, AppQualSubject, AppQualResult, AppLanguageSkills, AppPublicTransport, AppDrivingLicense, AppVehicleAccess, AppAttitude, AppLeisure, AppComputerSkills, AppWorkExperience, AppMainSkills, AppStudentNotes, AppliedDate FROM [Student_Applications$]";
connection.Open();
using (DbDataReader dr = command.ExecuteReader())
{
while (dr.Read())
{
if (Step.Students.FindByApplicationID(Int32.Parse(dr["ApplicationID"].ToString())) == null)
{
Step.Students.AddStudentsRow(
Int32.Parse(dr["ApplicationID"].ToString()),
Int32.Parse(dr["StudentID"].ToString()),
0,
Int32.Parse(dr["AppEligibleCurrentYear"].ToString()),
(dr["AppForename"].ToString()), (dr["AppSurname"].ToString()),
(dr["AppAddress1"].ToString()), (dr["AppAddress2"].ToString()),
(dr["AppAddress3"].ToString()), (dr["AppCity"].ToString()),
(dr["Email"].ToString()), (dr["Phone"].ToString()),
(dr["AppPostCode"].ToString()), (dr["AppTermAddress1"].ToString()),
(dr["AppTermAddress2"].ToString()), (dr["AppTermAddress3"].ToString()),
(dr["AppTermCity"].ToString()), (dr["AppTermPostCode"].ToString()),
(dr["AppDOB"].ToString()), (dr["AppUniversityName"].ToString()),
(dr["AppUniversityNameNotListed"].ToString()), (dr["AppCourseName"].ToString()),
(dr["AppQualSubject"].ToString()), (dr["AppQualResult"].ToString()),
(dr["AppLanguageSkills"].ToString()), Int32.Parse(dr["AppPublicTransport"].ToString()),
Int32.Parse(dr["AppDrivingLicense"].ToString()), Int32.Parse(dr["AppVehicleAccess"].ToString()),
(dr["AppAttitude"].ToString()), (dr["AppLeisure"].ToString()),
(dr["AppComputerSkills"].ToString()), (dr["AppWorkExperience"].ToString()),
(dr["AppMainSkills"].ToString()), (dr["AppStudentNotes"].ToString()),
DateTime.Parse(dr["AppliedDate"].ToString()), DateTime.Now);
count++;
Mail Msg = new Mail();
string preface = dr["AppPostCode"].ToString().Substring(0, 2).ToUpper();
if (Step.PostCode.FindByPostCode(preface) == null)
{
PostCode PostCodeCheck = new PostCode(preface);
if (PostCodeCheck.ShowDialog() == DialogResult.OK)
{
Msg.sendSuccess(dr["Email"].ToString());
}
else
{
Msg.sendFailure(dr["Email"].ToString());
}
}
else
{
Msg.sendSuccess(dr["Email"].ToString());
}
}
dr.NextResult();
}
}
}
}
MessageBox.Show(count + " students were successfully added to the database.", "Update Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}