This is my second c# program and the database stuff is quite different than vb 6.0, I am
obviously missing a line or otherwise have malformed code -- Help!
Program is supposed to read in FCC Amateur Radio DB (flat file) and insert data into
an Access Database. DB has a defined primary key. Everything appears to work ok,
except when putting the dataset back in the DB file, I get a program exception!!!
I do have a catch block that does not help me much wrt to debug, anything I can add to make my debugging easier? The braces do not necessarily match up due to cut and paste. Program does build w/o errors and run ok, till line identifed below.
Thanks, Chuck
OleDbConnection conn = new OleDbConnection(@"Provider = Microsoft.Jet.OLEDB.4.0;" +
"User Id=;Password=;" + "Data Source=" + DestinationFile);
conn.Open();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter("Select * FROM Entity", conn);
//Create a new dataset
DataSet dsHams = new DataSet();
dataAdapter.Fill(dsHams,"Entity");
DataTable dtEntity = dsHams.Tables["Entity"];
//Close connection as dataAdapter has copy of records in dsHams
conn.Close();
{
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader(textFlatFile.Text))
{
long nRecs = new long();
long rowPosition = new long();
nRecs = 0;
rowPosition = 0;
string line;
InitializeComponent();
txtStatusBar.Text = "Processing DB records...";
// ***************************************************
// Major Loop to read FCC DB and split fields for inclusion intoDB
// ***************************************************
while ((line = sr.ReadLine()) != null | bStopFlag == true)
{
++nRecs;
if (Convert.ToInt64(nRecs) % 10000 == 0)
{ Console.WriteLine(Convert.ToString(nRecs)); }
string[] sTokens = line.Split(new char[] { '|' });
DataRow rwNextHam = dtEntity.NewRow();
//field values...see FCC: EN.DAT
rwNextHam["Record_Type"] = "EN";
rwNextHam["Unique_System_Identifier"] = sTokens[1];
rwNextHam["Call_Sign"] = sTokens[4];
dtEntity.Rows.Add(rwNextHam);
rowPosition = dtEntity.Rows.Count - 1;
}
//fails at next line, "dtEntity" contains 976,500 records
//which is what the table should approx. contain
dataAdapter.Update(dsHams, "Entity"); [B]<---Fails here,exception[/B]
.
.
.
//separate catch block, anything I can add that will help me decipher problem
catch (Exception )
{
Console.WriteLine("Error: {0}");
//return;
goto nextRecord;
}
nextRecord: ;