Does anyone know how to query a table and get the schema
informationback as well as the values in the fields. Here is what I
have done so far. I cannot get both.
using (SqlConnection conF = new
SqlConnection ( "server=" + srvr +
";Integrated Security=SSPI;database=" + dbName +
";Initial Catalog=" + tblNames[tbl].ToString
( )))
{
conF.Open ( );
SqlCommand sqlCmd = new SqlCommand ( );
sqlCmd = conF.CreateCommand ( );
sqlCmd.CommandText = "SELECT * FROM
INFORMATION_SCHEMA.COLUMNS";
SqlDataReader sqlDr = sqlCmd.ExecuteReader ( );
int fc = 0;
if (sqlDr.FieldCount 0)
{
while (sqlDr.Read ( ))
{
fc++;
for (int h = 0; h <= sqlDr.FieldCount - 1;
h++)
{
Debug.WriteLine ( sqlDr[h].ToString ( )
);
}
//foreach (DataRow dr in dt.Rows)
//{
// //Debug.WriteLine ( dr[x] );
// foreach (DataColumn dc in dt.Columns)
// {
// Debug.WriteLine ( dc.ColumnName +
" Value: " + sqlDr[x].ToString() );
// x++;
// }
//}
}
}
conF.Close ( );