How to use SQL Connection Class in Windows Forms Application

Jun 8 2018 2:50 AM
Hello Guys!
 
I got adopted this code from this website written by Hammad Maqbool. I found it very interesting but i just want to clarify if how would i going to use this in Windows Forms Applications like in "Try" Statement.
 
This is the class i modified:
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using MySql.Data.MySqlClient;  
  7. using System.Data;  
  8.   
  9. namespace myssfasys  
  10. {  
  11.     public class myconnstring1  
  12.     {  
  13.         string ConnString = "Server=localhost; User Id=root; Password=deityshasm911; Database=ssfasys";  
  14.         MySqlConnection con;  
  15.   
  16.         public void OpenConection()  
  17.         {  
  18.             con = new MySqlConnection(ConnString);  
  19.             con.Open();  
  20.         }  
  21.   
  22.   
  23.         public void CloseConnection()  
  24.         {  
  25.             con.Close();  
  26.         }  
  27.   
  28.   
  29.         public void ExecuteQueries(string Query_)  
  30.         {  
  31.             MySqlCommand cmd = new MySqlCommand(Query_, con);  
  32.             cmd.ExecuteNonQuery();  
  33.         }  
  34.   
  35.   
  36.         public MySqlDataReader DataReader(string Query_)  
  37.         {  
  38.             MySqlCommand cmd = new MySqlCommand(Query_, con);  
  39.             MySqlDataReader dr = cmd.ExecuteReader();  
  40.             return dr;  
  41.         }  
  42.   
  43.   
  44.         public object ShowDataInGridView(string Query_)  
  45.         {  
  46.             MySqlDataAdapter dr = new MySqlDataAdapter(Query_, ConnString);  
  47.             DataSet ds = new DataSet();  
  48.             dr.Fill(ds);  
  49.             object dataum = ds.Tables[0];  
  50.             return dataum;  
  51.         }    
  52.     }  
  53. }  
 I'm just new with programming so please i need help.

Answers (2)