Skip to content

Commit 877c15f

Browse files
authored
Merge pull request #5 from alosslessdev/alosslessdev
progreso en conexion a bases de datos, correcion de texto
2 parents 18f868b + fe3adfb commit 877c15f

4 files changed

Lines changed: 132 additions & 2 deletions

File tree

ConexionBaseDeDatos.cs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Data.SqlClient;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Lab_6
10+
{
11+
internal class ConexionBaseDeDatos
12+
{
13+
14+
private string detallesConexion = "Data Source=localhost;Initial Catalog=Libreria;Integrated Security=True";
15+
16+
public DataSet ObtenerDatos()
17+
{
18+
DataSet datos = new DataSet();
19+
try
20+
{
21+
using (SqlConnection conexion = new SqlConnection(detallesConexion))
22+
{
23+
string query = "SELECT Nombre, Departamento, Salario FROM Empleados";
24+
SqlDataAdapter adaptador = new SqlDataAdapter(query, conexion);
25+
adaptador.Fill(datos, "Libros");
26+
}
27+
}
28+
catch (SqlException ex)
29+
{
30+
throw new Exception("Error al obtener libros: " + ex.Message);
31+
}
32+
33+
return datos;
34+
35+
}
36+
37+
public DataSet InsertDatos()
38+
{
39+
DataSet datos = new DataSet();
40+
try
41+
{
42+
using (SqlConnection conexion = new SqlConnection(detallesConexion))
43+
{
44+
string query = "SELECT Nombre, Departamento, Salario FROM Empleados";
45+
SqlDataAdapter adaptador = new SqlDataAdapter(query, conexion);
46+
adaptador.Fill(datos, "Libros");
47+
}
48+
}
49+
catch (SqlException ex)
50+
{
51+
throw new Exception("Error al obtener libros: " + ex.Message);
52+
}
53+
54+
return datos;
55+
56+
}
57+
58+
public DataSet UpdateDatos()
59+
{
60+
DataSet datos = new DataSet();
61+
try
62+
{
63+
using (SqlConnection conexion = new SqlConnection(detallesConexion))
64+
{
65+
string query = "SELECT Nombre, Departamento, Salario FROM Empleados";
66+
SqlDataAdapter adaptador = new SqlDataAdapter(query, conexion);
67+
adaptador.Fill(datos, "Libros");
68+
}
69+
}
70+
catch (SqlException ex)
71+
{
72+
throw new Exception("Error al obtener libros: " + ex.Message);
73+
}
74+
75+
return datos;
76+
77+
}
78+
79+
public DataSet DeleteDatos()
80+
{
81+
DataSet datos = new DataSet();
82+
try
83+
{
84+
using (SqlConnection conexion = new SqlConnection(detallesConexion))
85+
{
86+
string query = "SELECT Nombre, Departamento, Salario FROM Empleados";
87+
SqlDataAdapter adaptador = new SqlDataAdapter(query, conexion);
88+
adaptador.Fill(datos, "Libros");
89+
}
90+
}
91+
catch (SqlException ex)
92+
{
93+
throw new Exception("Error al obtener libros: " + ex.Message);
94+
}
95+
96+
return datos;
97+
98+
}
99+
100+
}
101+
102+
103+
104+
}

Form1.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lab#6.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<Reference Include="System.Xml" />
4747
</ItemGroup>
4848
<ItemGroup>
49+
<Compile Include="ConexionBaseDeDatos.cs" />
4950
<Compile Include="Form1.cs">
5051
<SubType>Form</SubType>
5152
</Compile>

Lab#6.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.11.35219.272
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab#6", "Lab#6.csproj", "{973302B8-6227-4C64-AEC6-F4C1AEB6E2B9}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{973302B8-6227-4C64-AEC6-F4C1AEB6E2B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{973302B8-6227-4C64-AEC6-F4C1AEB6E2B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{973302B8-6227-4C64-AEC6-F4C1AEB6E2B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{973302B8-6227-4C64-AEC6-F4C1AEB6E2B9}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {28E60DC4-2A50-43F1-A839-A566C2ED5CCF}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)