zaterdag 3 oktober 2009

Get column names from a SQL table

DataTable dtColumnNames = new DataTable();
SqlCommand command = new SqlCommand();
SqlConnection connection = GetConnection();
string commandText = "SELECT name FROM sys.syscolumns WHERE (id = OBJECT_ID(@Table))";
command.Connection = connection;
command.CommandText = commandText;
command.Parameters.Add(new SqlParameter("@Table", tableName));
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(dtColumnNames);

Geen opmerkingen:

Een reactie posten