Search This Blog

Friday, November 26, 2010

Create and populate a DataTable manually.

Create and populate a DataTable manually.

DataTable table = new DataTable();
table.TableName = "SelectedMinOcc";
table.Columns.Add("ID", typeof(Int32));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("LAT", typeof(double));
table.Columns.Add("LONG", typeof(double));

foreach (DataGridViewRow row in dgvSearchResults.SelectedRows)
{
table.Rows.Add(Convert.ToInt32(row.Cells["ID"].Value)
, Convert.ToString(row.Cells["Name"].Value)
, Convert.ToDouble(row.Cells["LAT"].Value)
, Convert.ToDouble(row.Cells["LONG"].Value)
);
}

Monday, November 22, 2010

Read Windows Registry settings for VB and VBA Projects

My continuing exercise in comparative languages VB6 vs C#

Read Windows Registry settings for VB and VBA Projects

VB6
GetSetting("DRC", "Config", "DRC_CD")

C#

using Microsoft.Win32;

RegistryKey DRCKEY = Registry.CurrentUser.OpenSubKey("Software\\VB and VBA Program Settings\\DRC\\Config");
object CDPath = DRCKEY.GetValue("DRC_CD");

Wednesday, November 17, 2010

Here is something I have not done in awhile - Cmd batch file

Recently, I have to simply deployment of a services patch with a batch file to uninstall current servce.exe (written in 1.1 .ner framework



: DATE: 11/17/2020 ENG: GLK  
: This batch file uninstalls the Fusion RIS Delivery Service that supports Esker 3.5 FP1

echo.
echo uninstall existing Fusion RIS Delivery Service
%WINDIR%\Microsoft.NET\Framework\v1.1.4322\InstallUtil.exe DeliveryService.exe /u

echo.
IF EXIST EDDSAT.dll echo Unregistering EDDSAT.dll
IF EXIST EDDSAT.dll %WINDIR%\SYSTEM32\RegSvr32.exe EDDSAT.dll /u 



And then  I used this batch to register the service again. 


 : DATE: 11/17/2020 ENG: GLK 
: This batch file installs the new Fusion RIS Delivery Service that supports Esker 5.0

echo.
echo installing new Fusion RIS Delivery Service
%WINDIR%\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe DeliveryService.exe

echo.
echo Registering EDDSAT.dll
%WINDIR%\SYSTEM32\RegSvr32.exe EDDSAT.dll
 

Tuesday, November 16, 2010

Host file location in Windows

Try to locate any existing hosts file on your computer: 
 
Windows 95/98/Me c:\windows\hosts
Windows NT/2000/XP Pro  c:\winnt\system32\drivers\etc\hosts
Windows XP Home c:\windows\system32\drivers\etc\hosts
 
(you may need administrator access for Windows NT/2000/XP)

Saturday, November 6, 2010

Change Context menu items on the fly

The example using the contextMenuStrip on a winforms form.
Purpose is to use a single contextStripMenu but have the list of menu items change based in the control associated with.

cmsMap = ContextMenuStrip control which is as the contextmenu for tabcontrol1 and drcMapControl1.

void cmsMap_Opening(object sender, CancelEventArgs e)
{
   //Set all visible to all menu items to false
   (sender as ContextMenuStrip).Items["moveTabsToTopToolStripMenuItem"].Visible = false;
   (sender as ContextMenuStrip).Items["moveTabsToBottomToolStripMenuItem"].Visible = false;
   (sender as ContextMenuStrip).Items["addLabelToolStripMenuItem"].Visible = false;

  //Based on the sender.SourceControl make specific menu items visible.
  switch ((sender as ContextMenuStrip).SourceControl.Name)
  {
    case "drcMapControl1":
     (sender as ContextMenuStrip).Items["addLabelToolStripMenuItem"].Visible = true;
        break;
    case "tabControl1":
     (sender as ContextMenuStrip).Items["moveTabsToTopToolStripMenuItem"].Visible = true;
     (sender as ContextMenuStrip).Items["moveTabsToBottomToolStripMenuItem"].Visible = true;
     switch (tabControl1.Alignment)
     {
         case TabAlignment.Bottom:
        (sender as ContextMenuStrip).Items["moveTabsToBottomToolStripMenuItem"].Visible = false;
               break;
         case TabAlignment.Top:
         (sender as ContextMenuStrip).Items["moveTabsToTopToolStripMenuItem"].Visible = false;
                break;
         default:
               break;
    }
        break;
    default:
         break;
    }
}





Tuesday, November 2, 2010

List all constraints for a table in SQL 2005/2008

--Find Constraints for a table
SELECT *
FROM sys.all_objects
WHERE type in ('F','PK') and parent_object_id in (
SELECT object_id from sys.all_objects WHERE Type= 'U' and name= 'tbPatients')

Monday, November 1, 2010

Query tables containing same column name

I use this type of query all the time...

SELECT o.name, o.xtype, c.name, c.length, c.type
FROM sysobjects o
INNER JOIN syscolumns c on o.id = c.id
WHERE ((c.name ='CPTCode' AND o.xtype='U') OR o.name = 'tbcdCPTCodes' and c.name ='Code')
ORDER by o.name