//*****
//TODO: unwire any event handlers that will be triggered by a rebind
//*****
GridHelper.UnregisterDatagridEvents(ref datagrid1);
System.Data.SqlServerCe.SqlCeCommand cmdSql = new System.Data.SqlServerCe.SqlCeCommand();
cmdSql.Connection = myStaticGlobals.LocalConnection;
System.Data.SqlServerCe.SqlCeResultSet ceResults = null;
SelectedContext visitContext = myStaticGlobals.SelectedData.FindContext("Visit", false);
if ((visitContext.SelectedId == null) || (visitContext.SelectedTable == null))
MessageBox.Show("No visit selected.");
else
{
cmdSql.CommandText =
string.Format("select column1, column2 from table1 inner join {0} as visits where visits.id = {1}", visitContext.SelectedTable, (Int64)visitContext.SelectedId);
////TODO: add DataGridStyle?
try
{
if (this.datagrid1.DataSource != null)
{
((System.Data.SqlServerCe.SqlCeResultSet)this.datagrid1.DataSource).Close();
((System.Data.SqlServerCe.SqlCeResultSet)this.datagrid1.DataSource).Dispose();
}
ceResults = cmdSql.ExecuteResultSet(System.Data.SqlServerCe.ResultSetOptions.Scrollable | System.Data.SqlServerCe.ResultSetOptions.Insensitive); //<-- error thrown here
this.datagrid1.DataSource = ceResults;
this.datagrid1.TableStyles.Clear();
DataGridTableStyle hideId = new DataGridTableStyle();
this.datagrid1.TableStyles.Add(hideId);
hideId.GridColumnStyles[0].Width = -1;
}
catch (System.Data.SqlServerCe.SqlCeException exSql)
{
if (exSql.Message.IndexOf("not exist") > 0)
MessageBox.Show("Please re-sync all device data.");
else
MessageBox.Show(exSql.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//*****
//TODO: Re-wire any event handlers for trickle-down effect and fire them
//*****
GridHelper.RegisterDatagridEvents(ref datagrid1);
|