Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1.         public void Ingresar(Categoria categoria)
  2.         {
  3.             string sql = "INSERT INTO CATEGORIAS (nombre, descripcion, subcategoria) VALUES (@nombre,@descripcion,@subcategoria)";
  4.  
  5.             SqlParameter nombreParameter = new SqlParameter("nombre", SqlDbType.NVarChar)
  6.             {
  7.                 Value = categoria.Nombre
  8.             };
  9.  
  10.             SqlParameter descripcionParameter = new SqlParameter("descripcion", SqlDbType.Text)
  11.             {
  12.                 Value = categoria.Descripcion
  13.             };
  14.  
  15.             SqlParameter subcategoriaParameter = new SqlParameter("subcategoria", SqlDbType.Int)
  16.             {
  17.                 Value = categoria.Subcategoria
  18.             };
  19.  
  20.             List<SqlParameter> sqlParameters = new List<SqlParameter>
  21.             {
  22.                 nombreParameter,
  23.                 descripcionParameter,
  24.                 subcategoriaParameter
  25.             };
  26.  
  27.             try
  28.             {
  29.                 connection.ExecuteSQL(sql, sqlParameters);
  30.             }
  31.             catch (Exception e)
  32.             {
  33.                 Console.WriteLine("An exception has occurred. " + e.Message);
  34.             }
  35.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement