sqldatareader

DataReader cursor rewind

ぃ、小莉子 提交于 2019-12-04 04:10:10
问题 How do I can rewind a cursor of a DataReader to the beginning? With one DataReader result I need to run two while loop, but those have to be from beginning. They are two iterations in one result set running a query once. Example: dr = command.ExecuteReader(cmd); while (dr.Read()) { // do some... } // rewind cursor here while (dr.Read()) { // do another things... } I've looked into the DataReader docs and I've found nothing, so if it can't be possible with DataReader, I may change the class

SqlDataReader are these two the same Which one is faster

感情迁移 提交于 2019-12-04 03:38:39
问题 I am working with SqlXml and the stored procedure that returns a xml rather than raw data. How does one actually read the data when returned is a xml and does not know about the column names. I used the below versions and have heard getting data from SqlDataReader through ordinal is faster than through column name. Please advice on which is best and with a valid reason or proof sqlDataReaderInstance.GetString(0); sqlDataReaderInstance[0]; 回答1: and have heard getting data from SqlDataReader

Is closing/disposing an SqlDataReader needed if you are already closing the SqlConnection?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 03:37:19
问题 I noticed This question, but my question is a bit more specific. Is there any advantage to using using (SqlConnection conn = new SqlConnection(conStr)) { using (SqlCommand command = new SqlCommand()) { // dostuff } } instead of using (SqlConnection conn = new SqlConnection(conStr)) { SqlCommand command = new SqlCommand(); // dostuff } Obviously it does matter if you plan to run more than one command with the same connection, since closing an SqlDataReader is more efficient than closing and

ExecuteReader requires an open and available Connection. The connection's current state is closed

≡放荡痞女 提交于 2019-12-04 03:04:06
问题 Ok, I asked about this very error earlier this week and had some very helpful answers and without doubt things have drastically improved since I started following the suggestions. However, now I am using the 'correct', best practice method to access the database I still get this error on some functions and I cannot get it to disappear for that block. Here is my code: Public Shared Function doesBasketExist(ByVal baskethash As String) As Boolean Dim _r As Boolean Using db As New SqlConnection

Check if it's the last record in sqldatareader

时光怂恿深爱的人放手 提交于 2019-12-04 02:47:18
Is there a way to check if I'm on the last record ? thanks Raman Zhylich Use this pattern to identify and process the last row in result: if (reader.Read()) { var loop = true; while (loop) { //1. Here retrive values you need e.g. var myvar = reader.GetBoolean(0); loop = reader.Read(); if (!loop) { //You are on the last record. Use values read in 1. //Do some exceptions } else { //You are not on the last record. //Process values read in 1., e.g. myvar } } } Other than "there isn't another one afterwards", no. This may mean you need to buffer the row, try to read, then look at the buffered data

Is there any performance gain from CommandBehavior.SequentialAccess?

大憨熊 提交于 2019-12-04 02:19:29
I realized I always read my fields in the order they are returned by index (using constants). So my code is already compatible with CommandBehavior.SequentialAccess as far as i understand. Would there be any benefits if i turn it on? DataReader is already forward only, read only which is the real performance gain right? The main usage of this is when you are reading very large CLOB ( nvarchar(max) etc) or BLOB ( varbinary(max) ) fields. In the default usage, it buffers the entire row of data before letting you near it - which could mean it has to allocate a large buffer for any BLOB / CLOB

How to get the exact type of numeric columns incl. scale and precision?

这一生的挚爱 提交于 2019-12-03 14:04:19
Is there a way to know the exact type of a column in a DataTable ? Right now I am doing this: DataTable st = dataReader.GetSchemaTable(); foreach (DataColumn col in st.Columns) { var type = col.DataType; } Now with type.Name I am able to find if it is a number( int or decimal ..) or string but the problem is that I need the exact type, for example if in database let say column Rate is NUMBER(4,3) then here in my code I am only getting type as 'Decimal' and no information about the Format 4,3 . Now the requirement is I need to format the values as per their type for eg. if Rate=1.4 it should be

How to make streams from BLOBs available in plain old C# objects when using SqlDataReader?

老子叫甜甜 提交于 2019-12-03 13:42:48
问题 This is the scenario: We store files, e.g. relatively large documents (10-300MB), in blobs in our MSSQL database. We have a very small domain model so we use the clean SqlDataReader approach for our repository, instead of an ORM, to avoid unnecessary dependencies. We want to use the objects in server context on ASP.NET/ASP.NET MVC web pages. We do not want to temporarily store the blobs in byte[], to avoid high memory usage on the server So what I have been doing is to implement my own

C# SqlDataReader Execution Statistics and Information

▼魔方 西西 提交于 2019-12-03 13:36:11
问题 I am creating an automated DB Query Execution Queue, which essentially means I am creating a Queue of SQL Queries, that are executed one by one. Queries are executed using code similar to the following: using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString)) { cn.Open(); using (SqlCommand cmd = new SqlCommand("SP", cn)) { cmd.CommandType = CommandType.StoredProcedure; using (SqlDataReader dr = cmd.ExecuteReader()) {

ADO.NET Question: When to use DataReader, DataAdapter

坚强是说给别人听的谎言 提交于 2019-12-03 13:11:06
i just wondering, what things i have to consider when using DataReader and DataAdapter in fetching data from the database and whats the difference between this two other the datareader needs open connection and the datadapter does not... In our projects, were using DataReader in ALL our DAL, we never use dataadapter. So I wondering what scenario would it been better to use DataAdapter + Datatable combo than using DataReader. Thanks in advance. DataReader : This is best used when you just want to fetch data in readony mode , populate your business entity and close the reader. This is really