sqldatareader

Check for column name in a SqlDataReader object

﹥>﹥吖頭↗ 提交于 2019-12-16 23:34:14
问题 How do I check to see if a column exists in a SqlDataReader object? In my data access layer, I have create a method that builds the same object for multiple stored procedures calls. One of the stored procedures has an additional column that is not used by the other stored procedures. I want to modified the method to accommodate for every scenario. My application is written in C#. 回答1: public static class DataRecordExtensions { public static bool HasColumn(this IDataRecord dr, string

WebMatrix Database.Query with Custom CommandTimeout

梦想与她 提交于 2019-12-14 03:57:33
问题 Consider the following TestDb with TestTable and Procedure USE TestDb GO --DROP TABLE dbo.TestTable IF NOT EXISTS (SELECT 1 FROM sys.tables WHERE name = 'TestTable') BEGIN CREATE TABLE dbo.TestTable ( RecordId int NOT NULL IDENTITY(1,1) PRIMARY KEY , StringValue varchar(50) NULL , DateValue date NULL , DateTimeValue datetime NULL , MoneyValue money NULL , DecimalValue decimal(19,4) NULL , IntValue int NULL , BitValue bit NOT NULL ) INSERT INTO dbo.TestTable SELECT 'Test', CAST(GETDATE() AS

How to iterate through a large SQL result set with multiple related tables

早过忘川 提交于 2019-12-13 17:58:51
问题 I am retrieving a very large number of records with multiple result sets from SQL Server into my .NET 3.5 project. I can't just pull them all into a DataSet and work on them, since it would take up too much memory. I don't need to pull all the records as once but just one record in the parent table and then the related child records. I could accomplish this with using a DataReader but my concern here is the process of iterating through all the records will take many hours. That means the

mysqlexception was unhandled - There is already an open DataReader associated with this Connection which must be closed first

别等时光非礼了梦想. 提交于 2019-12-13 06:26:49
问题 So I am trying to use the form to update my database on xampp. But when I try update I get the error in the title at this part: reader = objcommand.ExecuteReader() All help is much appreciated. Here is the code: Imports MySql.Data Imports MySql.Data.MySqlClient Imports System.Drawing.Printing Imports System Imports System.Windows.Forms Public Class frmClientDetails Dim form_type As Form Dim user_table As String Dim objconnection As New MySqlConnection("Server=localhost;database=ba-solutions

Enforce only single row returned from DataReader

梦想与她 提交于 2019-12-12 10:29:24
问题 I seem to write this quite a lot in my code: using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { result = new User((int)reader["UserId"], reader["UserName"].ToString()); } if (reader.Read()) { throw new DataException("multiple rows returned from query"); } } Is there some built in way to do this that I don't know about? 回答1: I don't know, but this code can be delegated into an extension method: public static R Single<R>(this DataReader reader, Func<DataReader,R> selector) { R

Error: Invalid attempt to call Read when reader is closed after the while loop?

不想你离开。 提交于 2019-12-12 10:27:52
问题 Hello i have a method which reads some data from the sql and saves them to arrays. to find out how many rows the sql result has i wrote this: DataTable dt = new DataTable(); dt.Load(rdr); count = dt.Rows.Count; after that, the sqldatareader saves the results to arrays. here is my complete code: public BookingUpdate[] getBookingUpdates(string token) { String command = "SELECT b.ID,b.VERANSTALTER, rr.VON ,rr.BIS, b.THEMA, b.STORNO, ra.BEZEICHNUNG from BUCHUNG b JOIN RESERVIERUNGRAUM rr on rr

c# IDataReader SqlDataReader difference

[亡魂溺海] 提交于 2019-12-12 07:52:30
问题 Can someone tell me the difference between these two pieces of code? Why use IDataReader? using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { // get data from the reader } } using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { // get data from the reader } } 回答1: SqlDataReader implements the interface IDataReader . So do all other ADO.NET drivers (Oracle, MySql, etc). You can use IDataReader , so that if you plan to change database engine some

SQLDataReader does not identify the empty columns

扶醉桌前 提交于 2019-12-12 02:49:48
问题 So, I have a function which reads the result of a query that is used later on the program as it follows: connection.Open(); int combination; using (SqlCommand com1 = new SqlCommand()) { com1.Connection = connection; com1.CommandText = "select FinalComboId from relationTable where sourceCombo=@source and destinationCombo=@destination"; com1.Parameters.Add(new SqlParameter("@source",combo.ToString() ?? "")); com1.Parameters.Add(new SqlParameter("@destination", destination ?? "")); SqlDataReader

Populate dropdownlist with datareader from database

那年仲夏 提交于 2019-12-11 20:22:57
问题 Problem with populate specific dropdownlist values from database, i want to shows user all the current data from database tables to let them able to make changes, but i coulnd't shows the specific dropdownlist that user selected before. Im using linqdatasource to show all the dropdownlist value. public partial class Update : System.Web.UI.Page { string cs = Global.CS; DataClasses1DataContext db = new DataClasses1DataContext(); protected void Page_Load(object sender, EventArgs e) { if (!Page

Concept of handling SqlCommand in C#

孤街醉人 提交于 2019-12-11 20:07:57
问题 I'm trying to select a list of users from the database and send email to each of every users based on a condition isSent == false. After send email to them, the value of this false should be update to true. Below code is the way i retrieve list of users from database and call method sendEmail() to each of them. myConnection.Open(); //******* try { SqlDataReader myReader = null; string sql = "SELECT * FROM testTable where isSent = false"; SqlCommand myCommand = new SqlCommand(sql, myConnection