Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CommandBehavior.SchemaOnly
Message
 
 
À
29/07/2013 18:27:42
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01579375
Message ID:
01579385
Vues:
43
>What .NET version are you using?
>With my version - 4.5 - the table created by GetSchemaTable has a string column called DataTypeName.
>I don't see any DataType column.
>
>http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getschematable.aspx

Where used to be ability to add comment to Help topic - I don't see it anymore :(

In any case, who should I now speak with about this problem. Why did they remove that useful property????? Now how I am supposed to get the .NET type using this code?


UPDATE. I found that this works

Console.WriteLine("Column type: {0}", rdr.GetFieldType((int)r["ColumnOrdinal"]));

but it is quite complex.
 using (SqlDataReader sqlDataReader = command.ExecuteReader(CommandBehavior.SchemaOnly))
               {
                  DataTable tbl = sqlDataReader.GetSchemaTable();
                  foreach (DataRow r in tbl.Rows)
                  {
                     ColumnSchema colSchema = new ColumnSchema();
                     String readerColumnName = r["ColumnName"].ToString();
                     colSchema.ColumnName = readerColumnName;
                     colSchema.ColumnSize = r.Field<Int16>("ColumnSize");
                     colSchema.DataType = (Type)(r["DataType"]);
                     colSchema.DbType = (SqlDbType)(Convert.ToInt32(r["ProviderType"]));

                     columnTypes.Add(readerColumnName, colSchema);
                  }
                  TableSchema schema = new TableSchema(tableName, columnTypes);
                  tableSchema.Add(tableName, schema);
                  
               }
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform