MHSoft Ltd. Database developing, consulting

Stored Procedures fuer den Ms SQL-Server

View markus hohmann's profile on LinkedIn

C# and VB code examples about:
how to create procedures, tables, grant privileges etc. by using C# and ADO.NET

The examples are mostly pretty simple, but very frequently needed. It sucks to look for them.
So, here we go. First just a methode to create a table and after, - privileges will be set to it.


public void CreateTable (String strtblName, ref SqlCommand myCmd, ref SqlConnection myCnn)
{
string strSQL = "CREATE TABLE [dbo].[" + strtblName + "]" + "([IDNr][int] NOT NULL PRIMARY KEY CLUSTERED," + " [FldBit][bit], [FldSmallint][smallint],[OrderDate][datetime]," + " [FldChar][char](10),[FldNumeric][numeric](18, 0)NULL) ON [PRIMARY]";

try
{
myCnn.Open();
myCmd.Connection = myCnn;
myCmd.CommandText = strSQL;
myCmd.ExecuteNonQuery();
}

catch (Exception ex )
{
myCnn.Close();
//MessageBox.Show("error in Methode: CreateTable = " + ex.Message);
throw new Exception(ex.Message);

}
finally
{ myCnn.Close(); }
//This is a download for a the whole class, within a winform project. download
}
MHSoft Ltd. | UTR 623 17168 26211 A | Fax: (49) 0321 212 010 47
  • Suite 48 |  
  • 88 - 90 Hatton Garden London |  
  • EC1N 8PN United Kingdom |  
  • Email: markus[at]hohmannM.eu