SqlCeResultSet.GetSqlMetaData Method
Visual Studio 2010
Returns the metadata information associated with the specified column.
Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)
Parameters
- ordinal
- Type: System.Int32
The ordinal position of the column from which to retrieve data.
Return Value
Type: System.Data.SqlServerCe.SqlMetaDataThe metadata of the column at the specified index.
SqlCeConnection conn = null; try { File.Delete("Test.sdf"); SqlCeEngine engine = new SqlCeEngine("Data Source = Test.sdf"); engine.CreateDatabase(); conn = new SqlCeConnection("Data Source = Test.sdf"); conn.Open(); SqlCeCommand cmd = conn.CreateCommand(); cmd.CommandText = "CREATE TABLE myTable (col1 INT, col2 MONEY, col3 NVARCHAR(200))"; cmd.ExecuteNonQuery(); cmd.CommandText = "SELECT * FROM myTable"; SqlCeResultSet rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable | ResultSetOptions.Scrollable); SqlMetaData columnMetaData = rs.GetSqlMetaData(2 /*ordinal*/); MessageBox.Show("Column Name = " + columnMetaData.Name); MessageBox.Show("Max Length = " + columnMetaData.MaxLength); MessageBox.Show("Type = " + columnMetaData.SqlDbType); } catch (Exception e) { MessageBox.Show(e.Message); } finally { conn.Close(); }
