查询 删除 修改系统
来源:互联网 发布:手机切歌软件 编辑:程序博客网 时间:2024/04/30 00:40
前台代码
WebForm.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="查询_增删.WebForm2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr><td>学生编号</td>
<td>
<asp:TextBox ID="txtStudentId" runat="server"></asp:TextBox></td></tr>
<tr>
<td>学生姓名 </td><td>
<asp:TextBox ID="txtStudentName" runat="server"></asp:TextBox>
</td></tr>
<tr><td>班级编号</td><td>
<asp:TextBox ID="txtClassId" runat="server"></asp:TextBox>
</td></tr>
<tr><td>班主任姓名</td><td>
<asp:TextBox ID="txtBzrName" runat="server"></asp:TextBox>
</td></tr>
<tr><td>联系电话</td><td>
<asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>
</td></tr>
<tr><td>家庭住址</td><td>
<asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
</td></tr>
<tr>
<td><asp:Button runat="server" Text="添加" ID="BtnAdd" onclick="BtnAdd_Click" /></td>
<td> <asp:Button ID="BtnSelect" runat="server" Text="查询" onclick="BtnSelect_Click"
style="height: 21px" /></td>
<td>
<asp:Button ID="btnUpdate" runat="server" Text="修改" onclick="btnUpdate_Click"
style="height: 21px" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
后台代码
WebForm.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace 查询_增删
{
public partial class WebForm2 : System.Web.UI.Page
{
string strcon = @"Data Source=PC-20121114LMOU;Initial Catalog=News;Persist Security Info=True;User ID=sa;Password=842674";
protected void Page_Load(object sender, EventArgs e)
{
}
//插入
protected void BtnAdd_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO T_Students(StudentId,StudentName,ClassId,BzrName,Photo,Address) VALUES (NEWID(),@txtStudentName,@txtclassid,@txtbzrname,@txtphoto,@txtaddress)";
cmd.Parameters.AddWithValue("@txtStudentName", txtStudentName.Text);
cmd.Parameters.AddWithValue("@txtclassid", txtClassId.Text);
cmd.Parameters.AddWithValue("@txtbzrname", txtBzrName.Text);
cmd.Parameters.AddWithValue("@txtphoto", txtPhone.Text);
cmd.Parameters.AddWithValue("@txtaddress", txtAddress.Text);
cmd.ExecuteNonQuery();
conn.Close();
conn.Dispose();
}
//查询
protected void BtnSelect_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT StudentId,StudentName,ClassId,BzrName,Photo,Address FROM T_Students WHEREStudentId=@txtStudentId";
cmd.Parameters.Add(new SqlParameter("@txtStudentId", txtStudentId.Text.Trim()));
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
conn.Dispose();
//Response.Write(dt.Rows.Count);
txtStudentId.Text = Convert.ToString(dt.Rows[0]["StudentId"]);
txtStudentName.Text = Convert.ToString(dt.Rows[0]["StudentName"]);
txtClassId.Text = Convert.ToString(dt.Rows[0]["ClassId"]);
txtClassId.Text = Convert.ToString(dt.Rows[0]["ClassId"]);
txtBzrName.Text = Convert.ToString(dt.Rows[0]["BzrName"]);
txtPhone.Text = Convert.ToString(dt.Rows[0]["Photo"]);
txtAddress.Text = Convert.ToString(dt.Rows[0]["Address"]);
}
//修改
protected void btnUpdate_Click(object sender, EventArgs e)
{
string studentname = txtStudentName.Text;
string classid = txtClassId.Text;
string bzrname = txtBzrName.Text;
string photo = txtPhone.Text;
string address = txtAddress.Text;
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "UPDATE T_Students SET StudentName=@txtStudentName,ClassId=@txtclassid,BzrName=@txtbzrname,Photo=@txtphoto,Address=@txtaddress whereStudentId=@txtstudentid ";
cmd.Parameters.Add(new SqlParameter("@txtStudentName", txtStudentName.Text.Trim()));
cmd.Parameters.Add(new SqlParameter("@txtStudentId", txtStudentId.Text.Trim()));
cmd.Parameters.Add(new SqlParameter("@txtclassid", txtClassId.Text));
cmd.Parameters.Add(new SqlParameter("@txtbzrname", txtBzrName.Text));
cmd.Parameters.Add(new SqlParameter("@txtphoto", txtPhone.Text));
cmd.Parameters.Add(new SqlParameter("@txtaddress", txtAddress.Text));
if (cmd.ExecuteNonQuery() > 0)
{
Response.Write("更改成功");
}
cmd.Dispose();
conn.Dispose();
}
}
}
- 查询 删除 修改系统
- 做学生信息录入删除查询修改系统的心得
- DataTable查询、修改、删除
- XML 查询、添加、修改、删除
- XML 查询、添加、修改、删除
- JDBC添加、删除、修改、查询
- XML 查询、添加、修改、删除
- mongodb 增加、删除、修改、查询
- AngularJS 查询 删除 增加 修改
- 投票系统下载[包括单选,复选,查询,管理登陆可任意修改删除]
- android系统内置数据库SQLite的建库、建表、添加、删除、修改、查询等基本操作
- 11_图书信息管理系统_查询_添加_修改_删除
- linux 查询修改系统时间
- access sql语句查询、修改、删除
- DLPHI代码解释(添加.查询.修改.删除)
- 插入 修改 删除 查询 存储过程
- php查询、插入、删除、修改记录
- LINQ类添加删除修改查询方法
- 类成员函数作为多线程的入口函数的实现方法
- 获得本地时间指定时区
- css,html,js/jQuery开发小技巧汇总-更新中~
- ssh项目步骤
- 【android积累】ScrollView和ListView问题
- 查询 删除 修改系统
- JS改写ALERT
- Hoj 1448 Dungeon Master
- C语言 变量 长度
- opencms8.5.0-安装
- 大数据量高并发的数据库优化
- VB Printer对象
- ARM的中断向量表简介
- 获取Android状态栏高度的屡试不爽的方法