dbdatareader

Getting a constraints exception when loading a DataReader in a DataTable

守給你的承諾、 提交于 2019-12-24 17:55:55
问题 I run a Merge query against a SQL2008 db that returns the output from the merge using the following c# code: cmd.CommandText = query; if (conn.DBConn.State == ConnectionState.Closed) conn.DBConn.Open(); DbDataReader dbReader = cmd.ExecuteReader(); DataTable dt = new DataTable("Results"); dt.Load(dbReader); The last line throws an error: System.Data.ConstraintException - Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints. I

How to easily convert a DbDataReader object into something useful?

对着背影说爱祢 提交于 2019-12-23 04:53:36
问题 I am manually calling a stored procedure using an Entity Framework EntityConnection like so: DbConnection storeConnection = entityConnection.StoreConnection; DbCommand command = storeConnection.CreateCommand(); command.CommandText = "sp_GetMyComplexData"; command.CommandType = CommandType.StoredProcedure; DbDataReader reader = command.ExecuteReader(); The reason for this is that the entity framework doesn't easily support entities that don't directly map to tables or views. I found this

Generic DbDataReader to List<T> mapping

女生的网名这么多〃 提交于 2019-12-17 07:41:33
问题 I am having a slight issue (more like an annoyance) with my property binding data access classes. The problem is that the mapping fails when there exists no column in the reader for corresponding property in class. Code Here is the mapper class: // Map our datareader object to a strongly typed list private static IList<T> Map<T>(DbDataReader dr) where T : new() { try { // initialize our returnable list List<T> list = new List<T>(); // fire up the lamda mapping var converter = new Converter<T>

Generic DbDataReader to List<T> mapping

不羁岁月 提交于 2019-12-17 07:41:15
问题 I am having a slight issue (more like an annoyance) with my property binding data access classes. The problem is that the mapping fails when there exists no column in the reader for corresponding property in class. Code Here is the mapper class: // Map our datareader object to a strongly typed list private static IList<T> Map<T>(DbDataReader dr) where T : new() { try { // initialize our returnable list List<T> list = new List<T>(); // fire up the lamda mapping var converter = new Converter<T>

Why does ExecuteReader() pad strings with traling spaces?

試著忘記壹切 提交于 2019-12-11 00:17:39
问题 I have two queries: Q1: select name from presidents where country = 'USA' Q2: select 'Obama' as name from presidents where country = 'USA' When using System.Data.Odbc.OdbcCommandExecuteReader then the returned DbDataReader contains 'Obama' in case of Q1 and 'Obama ' in case of Q2. Why is the string padded with trailing spaces in case of Q2 and what is the remedy? Trimming is ugly and even wrong in some cases. I am using .Net Framework 3.5. Here is the test code OdbcCommand cmd = new