sqldatareader

Invalid attempt to call Read when reader is closed

↘锁芯ラ 提交于 2019-12-24 07:13:05
问题 I'm kind of struggling trying to get this datagrid to bind. Everytime I run my code, I get an error message stating, "Invalid attempt to call Read when reader is closed". I don't see where I am closing my reader. Can you please help me? My code for loading the datagrid is below: protected void LoadGrid() { using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["VTC"].ConnectionString; conn.Open(); string sql = "select * from roi

SqlDataReader: In this scenario, will the reader get closed?

僤鯓⒐⒋嵵緔 提交于 2019-12-24 03:48:15
问题 I am cleaning up the DataReaders in an old .NET 1.1 project that I inherited. The previous developer coded the data-access-layer in such a way that most of the DAL methods returned SqlDataReaders (thus leaving it up to the caller to properly call the .Close() or .Dispose() methods). I have come across a situation, though, where a caller is not catching the returned SqlDataReader (and therefore is not disposing of it properly). See the code below: Data Access Method: Public Shared Function

how do I retrieve multiple images from the database using c#

微笑、不失礼 提交于 2019-12-23 20:26:06
问题 I have a database of 9 images, which keep changing, so I cannot directly set the src in html <img> tag to display the 9 images, I have to pick them from the database and bind them accordingly. I'm able to retrieve and print 1 image using Response.BinaryWrite() , but not all 9. My byte[] gets only the 1st image from the db, here's the code, while (dr.Read()) { Response.ContentType = "image/jpg"; Response.BinaryWrite((byte[])(dr["fsImage"])); } How do I retrieve all 9 images, and how do I bind

Access a specific row in DataReader

醉酒当歌 提交于 2019-12-23 10:49:35
问题 I have a datareader to display a list of gameweeks in a js carousel. I need to be able to add an if statement to change the div class of the current gameweek. This is my current code: if (dReader.HasRows) { while (dReader.Read()) { gameweekList.Text += "<div class=\"item\"><h4>Gameweek " + (dReader["gameweekID"].ToString()) + "</h4></div>"; } } else { gameweekList.Text = "Error Finding Gameweeks"; } dReader.Close(); conn.Close(); In effect I want to add if(dreader[1]) then add the extra bit,

Parsing a decimal from a DataReader

孤者浪人 提交于 2019-12-23 09:38:45
问题 I found a workaround for this error, but am now really curious as to why this would be happening, was wondering if anyone else has had this error. My function is as follows: public void Blog_GetRating(int blogID, ref decimal rating, ref int voteCount) { // Sql statements // Sql commands if (DataReader.Read()) { // this line throws a 'Input string was not in a correct format.' error. rating = decimal.Parse(DataReader["Rating"].ToString()); // this works absolutly fine?! decimal _rating = 0;

Filling a DataGridView from SQLReader

雨燕双飞 提交于 2019-12-23 09:18:22
问题 Im a little stuck on some code that im writing An outline is that i am reading some data in from an SQL database and wantint to display it in a DataGridView on a form. I have confirmed that there is data being returned from the database but am unsure as to why this isnt appearing. I have followed a number of tutorials from the internet but so far non have worked here is my code Private Sub PopulateGrid() Dim Con As New SqlClient.SqlConnection Dim strCon As String = CropTrackMod.strConn Dim

How to wrap SqlDataReader with IObservable properly?

柔情痞子 提交于 2019-12-23 06:09:26
问题 I would like to explore the possibility to use IObservable<T> as a wrapper around a SqlDataReader . Until now we were using the reader to avoid materializing the entire result in the memory and we did so using blocking synchronous API. Now we want to try and use asynchronous API in conjunction with the .NET Reactive Extensions. However, this code will have to coexist with a synchronous code as adopting the asynchronous ways is a gradual process. We already know that this mix of synchronous

How to wrap SqlDataReader with IObservable properly?

筅森魡賤 提交于 2019-12-23 06:09:18
问题 I would like to explore the possibility to use IObservable<T> as a wrapper around a SqlDataReader . Until now we were using the reader to avoid materializing the entire result in the memory and we did so using blocking synchronous API. Now we want to try and use asynchronous API in conjunction with the .NET Reactive Extensions. However, this code will have to coexist with a synchronous code as adopting the asynchronous ways is a gradual process. We already know that this mix of synchronous

Task when all, connection is closing

亡梦爱人 提交于 2019-12-22 05:11:22
问题 I'm trying to execute multiple SqlDataReaders using Task.WhenAll. But when the tasks are awaited I get "System.InvalidOperationException: Invalid operation. The connection is closed". Creation of tasks: List<Task<SqlDataReader>> _listTasksDataReader = new List<Task<SqlDataReader>>(); _listTasksDataReader.Add(GetSqlDataReader1(10)); _listTasksDataReader.Add(GetSqlDataReader2(10)); SqlDataReader[] _dataReaders = await Task.WhenAll(_listTasksDataReader); My "SqlDataReader" methods: public Task

Task when all, connection is closing

空扰寡人 提交于 2019-12-22 05:11:20
问题 I'm trying to execute multiple SqlDataReaders using Task.WhenAll. But when the tasks are awaited I get "System.InvalidOperationException: Invalid operation. The connection is closed". Creation of tasks: List<Task<SqlDataReader>> _listTasksDataReader = new List<Task<SqlDataReader>>(); _listTasksDataReader.Add(GetSqlDataReader1(10)); _listTasksDataReader.Add(GetSqlDataReader2(10)); SqlDataReader[] _dataReaders = await Task.WhenAll(_listTasksDataReader); My "SqlDataReader" methods: public Task