I was able to update without any issues
I am not sure whether the latitude and the Longitude values you are passing is correct (37.51,-85.24??) . getting a system exception on your values saying its NOT VALID.
I tried with latitude=8.12345, Longitude=50.56789 and worked very well and the database is also updated, Please see the code below i have used
private void button1_Click(object sender, EventArgs e)
{
try
{
OleDbConnection thisConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db1.mdb");
thisConnection.Open();
OleDbCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = "SELECT * from tblMGRSAdded";
OleDbDataReader thisReader = thisCommand.ExecuteReader();
while (thisReader.Read())
{
Geographic geoF = new Geographic(Convert.ToDouble(thisReader["longitude"]), Convert.ToDouble(thisReader["latitude"]));
MGRS mgrs = (MGRS)geoF;
string mgrsStr = mgrs.Zone + mgrs.Band + " " + mgrs.Grid + " " +
mgrs.EastString.Substring(0, 4) + " " + mgrs.NorthString.Substring(0, 4);
OleDbCommand thisUpdateCommand = thisConnection.CreateCommand();
thisUpdateCommand.CommandText = "update tblMGRSAdded set MGRS='" + mgrsStr + "' where ID=" + thisReader["Id"].ToString();
thisUpdateCommand.ExecuteNonQuery();
MessageBox.Show(mgrsStr);
}
thisReader.Close();
thisConnection.Close();
MessageBox.Show("OK");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Console version of the solution - UPDATE 2
static void Main(string[] args)
{
try
{
OleDbConnection thisConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db1.mdb");
thisConnection.Open();
OleDbCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = "SELECT * from tblMGRSAdded";
OleDbDataReader thisReader = thisCommand.ExecuteReader();
while (thisReader.Read())
{
Geographic geoF = new Geographic(Convert.ToDouble(thisReader["longitude"]), Convert.ToDouble(thisReader["latitude"]));
MGRS mgrs = (MGRS)geoF;
string mgrsStr = mgrs.Zone + mgrs.Band + " " + mgrs.Grid + " " +
mgrs.EastString.Substring(0, 4) + " " + mgrs.NorthString.Substring(0, 4);
Console.WriteLine("\t{0}\t{1}\t{2}", thisReader["latitude"], thisReader["longitude"], mgrsStr);
using (OleDbCommand thisUpdateCommand = thisConnection.CreateCommand())
{
thisUpdateCommand.CommandText = "update tblMGRSAdded set MGRS='" + mgrsStr + "' where ID=" + thisReader["Id"].ToString();
thisUpdateCommand.ExecuteNonQuery();
}
}
thisReader.Close();
thisConnection.Close();
Console.WriteLine("COMPLETED!!!!!....Press any key to exit");
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine("ERROR!!!!!....Press any key to exit");
Console.ReadKey();
}
}