Advertisement
Jh0n-K3v1n

Coneccion MySql

Mar 19th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using MySql.Data.MySqlClient;
  4.  
  5.  
  6. namespace SistemasDeRegalos.Conexion
  7. {
  8.     public class coon
  9.     {
  10.         string cadena_conexion()
  11.         {
  12.             string cadena_funcion = "Server=127.0.0.1; Port=3306; Database=conquercol; Uid=root; Password=;";//
  13.             return cadena_funcion;
  14.         }
  15.  
  16.         // public DataSet dat = new DataSet();
  17.         public DataTable SELECCIONAR(string sql)
  18.  
  19.         {
  20.  
  21.             MySqlConnection sqlcon = new MySqlConnection(cadena_conexion());
  22.             MySqlCommand sqlcom1 = new MySqlCommand(sql, sqlcon);
  23.             MySqlDataAdapter datos = new MySqlDataAdapter(sqlcom1);
  24.  
  25.             DataTable tabla = new DataTable();
  26.  
  27.             try
  28.             {
  29.                 sqlcon.Open();
  30.                 datos.Fill(tabla);
  31.                 sqlcon.Close();
  32.                 sqlcom1.Dispose();
  33.                 return tabla;
  34.  
  35.             }
  36.             catch (Exception axc)
  37.             {
  38.  
  39.                 sqlcon.Close();
  40.                 sqlcom1.Dispose();
  41.                 return null;
  42.             }
  43.  
  44.  
  45.         }
  46.         public string insertar1(string sql)
  47.         {
  48.  
  49.             MySqlConnection sqlcon = new MySqlConnection(cadena_conexion());
  50.  
  51.             MySqlCommand sqlcom2 = new MySqlCommand(sql, sqlcon);
  52.             string rta = "NO";
  53.  
  54.             try
  55.             {
  56.                 sqlcon.Open();
  57.                 int filas = sqlcom2.ExecuteNonQuery();
  58.                 sqlcon.Close();
  59.                 if (filas > 0)
  60.                 {
  61.                     rta = "SI";
  62.                 }
  63.                 return rta;
  64.             }
  65.             catch (Exception axc)
  66.             {
  67.  
  68.                 return axc.Message.ToString();
  69.             }
  70.  
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement