[Solved] what does mean this code in c sharp c# [closed]


I’m guessing you’re getting something along the lines of “there is already an open reader associated with the current connection”, yes? If so, see the second part of the answer.


this what i dont understand

CustomerDS custDB = new CustomerDS();
custDB.Clear();
adap.Fill(custDB, "Customers"); 

The first line is trivial, and simply creates a new empty instance of what looks to be a “typed dataset”, that has something to do with customers. The main thing this line tells me is that somebody is still, for whatever reason, using DataSet. Have mercy on them – they know not what they do.

The second line does what it sounds like; see intellisense:

Clears the System.Data.DataSet of any data by removing all rows in all tables.

The main thing this line tells me is that whoever wrote it has forgotten that they only just created it, and that it doesn’t contain any data yet.

The third line uses a data adapter to populate custDB with the data from a table called “Customers” (HOWEVER! the code earlier instructed it to use a very specific select command, which actually looks at a table called “admin”).


If we instead look at the code marked // here is error

MySqlCommand cmd = mysqlclass.connection.CreateCommand();
cmd.CommandText = "SELECT * FROM admin ";
mysqlclass.connection.Open();
MySqlDataAdapter adap = new MySqlDataAdapter(cmd);
MySqlDataReader dataReader = cmd.ExecuteReader();

This executes a SQL query to obtain all values from a table called “admin”, via the reader API (a forewards-only stream of row data), but then completely ignores that reader. It doesn’t use it anywhere. Most notably, it also doesn’t consume the data, nor dispose the reader. The main thing this tells me is that the author has lost track of what they were doing. That open reader will cause problems. Delete the line:

MySqlDataReader dataReader = cmd.ExecuteReader();

Also: look into the using statement.

4

solved what does mean this code in c sharp c# [closed]