المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : SQLCE C# Not Selecting New Records



C# Programming
08-27-2009, 01:49 AM
I am developing a C# Windows Application which inserts data into a SQLCE database.

It inserts fine, that works great!

However, if i want to select the new record from the database, it comes back as a blank result. I can search for previous records before i opened the applications. Its as though the database opens a cached copy, and you can only insert into it.

Here is my current code. Has anybody else had similar issues.


private void button2_Click(object sender, EventArgs e)
{
if (txtAddRegistration.Text != "")
{
if (comboAircraft.Text != "")
{
if (comboAirline.Text != "")
{
if (combo********.Text != "")
{
int picyesorno;
string picloc;
if (txtAddPicLoc.Text == "")
{
picyesorno = 0;
picloc = "";
}
else
{
picyesorno = 1;
picloc = txtAddPicLoc.Text;
}
string InsertRegCommand = "INSERT INTO SPOTTINGLOG (registration, aircraft, airline, ********, date, pictured, picloc, comments) values('" + txtAddRegistration.Text + "','" + comboAircraft.Text + "','" + comboAirline.Text + "','" + combo********.Text + "'," + dateTimePicker1.Value.ToShortDateString() + "," + picyesorno + ",'" + picloc + "','" + txtAddComments.Text + "')";
string database = @"D:\Daniel\Documents\Visual Studio 2008\Projects\AviationSpottingLog\AviationSpottingLog\SpotData.sdf";
try
{
SqlCeConnection conn = new SqlCeConnection("Data Source=" + database);
conn.Open();
SqlCeCommand command = new SqlCeCommand();
command.Connection = conn;
command.CommandText = InsertRegCommand;
command.ExecuteNonQuery();
conn.Close();
}
catch
{

}
try
{
this.searchAfterAdd(txtAddRegistration.Text);
}
catch
{
MessageBox.Show("Search didnt work");
}
txtAddComments.Clear();
txtAddPicLoc.Clear();
txtAddRegistration.Clear();
comboAircraft.Text = "";
comboAirline.Text = "";
txtLabelAdded.Text = "Added";
AddStatus.Start();
}
else
{
MessageBox.Show("You must enter a ********.", "Insert Record", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("You must enter an airline.", "Insert Record", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("You must enter an aircraft type.", "Insert Record", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("You must enter a registration.", "Insert Record", MessageBoxButtons.OK, MessageBoxIcon.Error);
}


}

private void searchAfterAdd(string param)
{
this.spottingLogTableAdapter.Fill(this.spotSearchReg.SpottingLog, param);
}

private void btnSearch_Click(object sender, EventArgs e)
{
if (txtSearchReg.Text != "")
{
this.spottingLogTableAdapter.Fill(this.spotSearchReg.SpottingLog, txtSearchReg.Text);
}
else
{
MessageBox.Show("Please enter a registration to search for.\n\nIf you would like to view records for specific Airports, Airlines and Aircraft, go to 'Browse Data Lists' on the top menu.", "Enter Search Criteria", MessageBoxButtons.OK, MessageBoxIcon.Error);

}
}