Questions tagged [sqldatareader]

Provides a way of reading a forward-only stream of rows from a SQL Server database.

The SqlDataReader is a member of the .NET framework's System.Data.SqlClient family responsible for reading data from a SQL database. The SqlDataReader is created by calling the ExecuteReader() method of the SqlCommand object, instead of directly using a constructor.

While the SqlDataReader is being used, the associated SqlConnection is busy serving the SqlDataReader, and no other operations can be performed on the SqlConnection other than closing it. This is the case until the Close method of the SqlDataReader is called. For example, you cannot retrieve output parameters until after you call Close.

Changes made to a result set by another process or thread while data is being read may be visible to the user of the SqlDataReader. However, the precise behavior is timing dependent.

For optimal performance, SqlDataReader avoids creating unnecessary objects or making unnecessary copies of data. Therefore, multiple calls to methods such as GetValue return a reference to the same object. Use caution if you are modifying the underlying value of the objects returned by methods such as GetValue.

References

MSDN Article

1132 questions
-2
votes
1 answer

C# MySQL reader is not reading

I have a function that reads values from specified columns. It looks like this: private bool OpenConnection() // Just opens the connection. No error here. { try { conn.Open(); …
-2
votes
1 answer

Appending To List

Using C# how can I append to a List? I am wanting to run two seperate SQL Queries and store the results of both in my List. The first query returns Bill and Joe And the second query returns James and Charles But my…
-2
votes
2 answers

I need to loop through the email addresses in a table within a SQL Server database and all an Email

I was wondering if someone could help me. I've got a simple Suppliers table that has email addresses for my suppliers. I need to loop through the email addresses 'SuppEmail' in the Suppliers table in the SQL Server database SpecCars and send them…
Chuck
  • 11
  • 4
-2
votes
2 answers

I have menustrip and each of items have its combobox

I have menustrip and each of items have its combobox. At runtime I want combos to be loaded from sql database tables. I tried dataadapter but at runtime all combos are in blank. Please help me in this topic.
-2
votes
2 answers

C# SQL Login form error incorrect syntax

I am trying to make a login form application that when a user types into the two text boxes and presses the button my application checks the Username and Password columns of my TeacherDetails table and if they are present in the table it displays…
mot375
  • 99
  • 1
  • 13
-2
votes
1 answer

Unable to resolve open data reader error (needs closing)

Error: There is already an open DataReader associated with this Command which must be closed first The idea is for getMaxID() to return the highest value in the field + 1- setting this as a new ReportID (for now). However I keep getting the…
Nick
  • 37
  • 1
  • 1
  • 7
-2
votes
4 answers

Populate multiple text boxes with SqlDataReader

I am trying to populate 11 textboxes, using my database information. private void button5_Click(object sender, EventArgs e) { SqlConnection CN = new SqlConnection(); CN.ConnectionString = cons; try { CN.Open(); …
-2
votes
2 answers

Dynamically change button back color c#

I want to change with a timer helps the color of buttons contains in a flowLayoutPanel1. With my query code the color change right, but when the condition of query turn to false, my button don't change his color (when I create it I set the color to…
Mikykly
  • 15
  • 2
  • 4
-2
votes
1 answer

SqlDataReader parameter not working

I have a windows form that I am asking a user to enter a pcname in textbox1 and then trying to use SqlDataReader to the read from the database to get the pc ipaddress and then map the pc drive to my local pc. But for some reason when I use the…
user1836162
  • 59
  • 2
  • 4
  • 14
-2
votes
2 answers

Deallocation of SqlDataReader

I have a contractor that wrote code like this all over the place when we execute sql queries: sql.Append(string.Format("SELECT TableId FROM ps_SavedTables WHERE guid = '{0}'", guid)); using (IDataReader reader =…
cdub
  • 24,555
  • 57
  • 174
  • 303
-3
votes
1 answer

Best way to populate List from database in C#

I have 3 classes inherited from same class like class S1:X{} class S2:X{} class S3:X{} I need to write method to populate List from Sql database. Currently, i am using SqlDataReader to populate. Each class has about 35 properties and db result…
-3
votes
3 answers

c# Cannot implicitly convert type System.data.sqlclient.sqldatareader to system.data.sqlclient.sqldatadapter

It Says I Cannot implicitly convert type System.Data.SqlClient.SqlDataReader to System.Data.SqlClient.SqlDataAdapter:
stxy
  • 13
  • 4
-3
votes
1 answer

How can I send response from c# class file to MVC Controller

If my condition fails as rdr.HasRows == true, how can I respond my controller its fails public Employee DeleteEmpById(int key) { try { SqlCommand cmd = new SqlCommand("Sp_GetEmployeeById", con); cmd.CommandType =…
Md Ghousemohi
  • 197
  • 2
  • 13
-3
votes
3 answers

What this line does?

this is a piece of code from a register app which uses databases.Since i can say i know the basic principles of OOP , I understand this code EXCEPT FOR THE FIRST LINE. How can an object (reader) be a method(ExecuteReader()) of another object (cmd1)…
Lazu Razvan
  • 49
  • 2
  • 8
-3
votes
2 answers

Select SQL using c# error can someone guide this one

What I'm missing? I've got error: Sqlexception was unhandled by usercode SqlConnection con = new SqlConnection(MyConnectionString); SqlCommand objCmd; con.Open(); SqlDataReader dtReader; String strSQL; strSQL = "SELECT * FROM " +…
1 2 3
75
76