string connString="user id=JoeBlue;Password=admin;Initial Catalog=myDB;Data Source=serverax790;Connect Timeout=30" ;
SqlConnection con = null;
SqlCommand oCommand= null;
SqlDataAdapter DataAdapter = null;
// Retreive Schema to get columns properties
/////////////////////////////////////////////
SqlDataAdapter DataAdapter = new SqlDataAdapter();
DataTable dtTableForSchema = new DataTable("TableForScheme");
try
{
con = new SqlConnection(connString);
con.Open();
oCommand= new SqlCommand();
oCommand.Connection = con;
DataAdapter = new SqlDataAdapter();
DataTable dtSchema = new DataTable();
oCommand.CommandText = "SELECT TOP 0 * FROM " + "MySourceTable";
DataAdapter.SelectCommand = oCommand;
DataAdapter.FillSchema(dtSchema,SchemaType.Source);
foreach(DataColumn Col in SourceTable.Columns)
{
string sColName = Col.ColumnName;
System.Type type = Col.DataType;
}
}
catch(Exception e)
{
// Process error
}
finally
{
if (con !=null)
{
con.Close();
con.Dispose();
}
// same for oCommand and DataAdapter;
}