idatareader

How to mock IDataReader to test method which converts SqlDataReader to System.DataView

泄露秘密 提交于 2020-02-03 04:31:06
问题 I'm new to Moq and I'm struggling to write Unit Test to test a method which converts SqlDataAdapter to System.DataView . This is my method: private DataView ResolveDataReader(IDataReader dataReader) { DataTable table = new DataTable(); for (int count = 0; count < dataReader.FieldCount; count++) { DataColumn col = new DataColumn(dataReader.GetName(count), dataReader.GetFieldType(count)); table.Columns.Add(col); } while (dataReader.Read()) { DataRow dr = table.NewRow(); for (int i = 0; i <

How do I read HasRow then Update?

核能气质少年 提交于 2020-01-24 20:54:25
问题 Is it possible to read HasRow and then Update ? This is the code what I have tried so far : If conn.State = ConnectionState.Closed Then conn.Open() End If Dim sqlcmd As New MySqlCommand("SELECT * FROM tbl_online_attendance where employees_id = '" & lvRealAtt.Items(itms).SubItems(0).Text & "' and in_time = '" & lvRealAtt.Items(itms).SubItems(1).Text & "' ", conn) Dim dr As MySqlDataReader dr = sqlcmd.ExecuteReader If dr.HasRows Then Dim query As String query = "UPDATE tbl_online_attendance SET

Supplying stream as a source of data for a binary column when SqlBulkCopy is used

末鹿安然 提交于 2020-01-23 13:29:07
问题 If one needs to read data from SqlServer in a streamed fashion, there are some capabilities for that. Such as using SqlDataReader with CommandBehavior.SequentialAccess , and particularly when binary column data needs to be accessed there is the GetStream(int) method for that: var cmd = new SqlCommand(); cmd.Connection = connection; cmd.CommandText = @"select 0x0123456789 as Data"; using (var dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { dr.Read(); var stream = dr.GetStream(0); /

Supplying stream as a source of data for a binary column when SqlBulkCopy is used

大兔子大兔子 提交于 2020-01-23 13:28:09
问题 If one needs to read data from SqlServer in a streamed fashion, there are some capabilities for that. Such as using SqlDataReader with CommandBehavior.SequentialAccess , and particularly when binary column data needs to be accessed there is the GetStream(int) method for that: var cmd = new SqlCommand(); cmd.Connection = connection; cmd.CommandText = @"select 0x0123456789 as Data"; using (var dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) { dr.Read(); var stream = dr.GetStream(0); /

MySqlConversionException when accessing DateTime field from DataReader

天大地大妈咪最大 提交于 2020-01-02 04:10:10
问题 I have a C# application over MySql, using MySQL Connector; I'm trying to make a DataReader request, the query executes fine, however, when trying to access a DateTime field, i'm getting MySqlConversionException {"Unable to convert MySQL date/time value to System.DateTime"} this is the prototype if (dr != null && !dr.Read()) return; sesion.Id = Convert.ToInt32(dr["id"]); sesion.Usuario = Convert.ToInt32(dr["usuario"]); sesion.Estado = Convert.ToByte(dr["estado"]); // doesn't work sesion

Checking for Nulls on DB Record Mapping

此生再无相见时 提交于 2020-01-01 17:58:20
问题 How can I check for db null values in the attached code? Please understand I am a new C# convert... What this code does is takes a IDataReader object and converts and maps it to a strongly-typed list of objects. But what I am finding is it completely errors out when there are null columns returned in the reader. Converter internal class Converter<T> where T : new() { // Declare our _converter delegate readonly Func<IDataReader, T> _converter; // Declare our internal dataReader readonly

AutoMapper with a list data from IDataReader

风格不统一 提交于 2019-12-22 17:54:15
问题 using (IDataReader dr = DatabaseContext.ExecuteReader(command)) { if (dr.Read()) { AutoMapper.Mapper.CreateMap<IDataReader, ProductModel>(); return AutoMapper.Mapper.Map<IDataReader, IList<ProductModel>>(dr); } return null; } if dr has only one row -> error: threw an exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' if dr has more than one row, it run ok . any help? 回答1: The problem is that Automapper is calling Read() as well - so is trying to always look at the

How do I use automapper to map a dataset with multiple tables

杀马特。学长 韩版系。学妹 提交于 2019-12-18 16:11:11
问题 DISCLAIMER: this is a copy paste from an older stackoverflow post that isn't available anymore, but I have exaclty the same problem, so it seemed appropriate to repost it as it was never answered. I have a stored procedure that will return 4 result sets (contacts, addresses, email, phones) which is populated into a dataset. I would like to use AutoMapper to populate a complex object. public class Contact { public Guid ContactId { get; set; } public string FirstName { get; set; } public string

How do I use automapper to map a dataset with multiple tables

冷暖自知 提交于 2019-12-18 16:11:02
问题 DISCLAIMER: this is a copy paste from an older stackoverflow post that isn't available anymore, but I have exaclty the same problem, so it seemed appropriate to repost it as it was never answered. I have a stored procedure that will return 4 result sets (contacts, addresses, email, phones) which is populated into a dataset. I would like to use AutoMapper to populate a complex object. public class Contact { public Guid ContactId { get; set; } public string FirstName { get; set; } public string

DataReader ordinal-based lookups vs named lookups

☆樱花仙子☆ 提交于 2019-12-18 05:04:07
问题 Microsoft (and many developers) claim that the SqlDataReader.GetOrdinal method improves the performance of retrieving values from a DataReader versus using named lookups ie. reader["ColumnName"]. The question is what is the true performance difference if dealing with small, paged record sets? Is it worth the extra overhead of finding and referencing ordinal indexes throughout the code? 回答1: Microsoft recommends not calling GetOrdinal within a loop. That would include indirect calls with the