Retrieve all rows in MySQL stored procedure and put in in C# class.
-
Hi everyone! My C# Project is using MySQL stored procedure to execute sql query. My question is How will I retrieve all rows in select * statement and put in a class? For example. [Row column]..........[Class 'User' member] user_name -----> userName user_id ---------> userID I do not have idea at all since I am new to this C# and MySQL tandem. Thank you in advance.
-
Hi everyone! My C# Project is using MySQL stored procedure to execute sql query. My question is How will I retrieve all rows in select * statement and put in a class? For example. [Row column]..........[Class 'User' member] user_name -----> userName user_id ---------> userID I do not have idea at all since I am new to this C# and MySQL tandem. Thank you in advance.
I would have a read through these, it shows you how to call a stored procedure from MySQL Calling a stored procedure from MySQL in C#[^] http://dev.mysql.com/doc/refman/5.0/en/connector-net-programming-stored.html[^]
Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON
-
Hi everyone! My C# Project is using MySQL stored procedure to execute sql query. My question is How will I retrieve all rows in select * statement and put in a class? For example. [Row column]..........[Class 'User' member] user_name -----> userName user_id ---------> userID I do not have idea at all since I am new to this C# and MySQL tandem. Thank you in advance.
MySqlCommand cmd = new MySqlCommand("ProcName", new MySqlConnection("ConnectoinStringHere")); // ProcName should be the name of the procedure which you want to call cmd.CommandType = CommandType.StoredProcedure; cmd.Connection.Open(); MySqlDataReader dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection); // Now you have all the data in the dataReader. So, you can loop through the datareader like while (dataReader.Read()) { string name = dataReader["Name"].ToString(); // this will store the Name (which is a column_name in the database) to a local variable } dr.Close(); But it is suggested to not get the full data of a table into the memory unless you really require it.