-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodificacion.aspx.cs
53 lines (49 loc) · 1.94 KB
/
modificacion.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class modificacion : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void find_Click(object sender, EventArgs e)
{
string s = System.Configuration.ConfigurationManager.ConnectionStrings["cadenaconexion1"].ConnectionString;
SqlConnection conexion = new SqlConnection(s);
conexion.Open();
SqlCommand comando = new SqlCommand("select dni,apellidonom,provincia from alumnos " +
" where dni='" + this.dni.Text + "'", conexion);
SqlDataReader registro = comando.ExecuteReader();
if (registro.Read())
{
this.name.Text = registro["apellidonom"].ToString();
this.state.Text = registro["provincia"].ToString();
}
else
this.Label1.Text = "No existe un alumno con ese dni";
conexion.Close();
}
protected void modify_Click(object sender, EventArgs e)
{
string s = System.Configuration.ConfigurationManager.ConnectionStrings["cadenaconexion1"].ConnectionString;
SqlConnection conexion = new SqlConnection(s);
conexion.Open();
SqlCommand comando = new SqlCommand("update alumnos set " +
"apellidonom='" + this.name.Text +
"',provincia='" + this.state.Text +
"' where dni='" + this.dni.Text + "'", conexion);
int cantidad = comando.ExecuteNonQuery();
if (cantidad == 1)
this.Label2.Text = "Datos Modificados";
else
this.Label2.Text = "No existe el usuario";
conexion.Close();
}
}
}