insert update delete Table.aspx.cs
来源:互联网 发布:java取两位小数 编辑:程序博客网 时间:2024/05/22 13:46
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;
namespace demo3
{
public partial class insertDeleteUpdateTable : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnInsert_Click(object sender, EventArgs e)
{
//1连接字符串
string constr = "data source=.;initial catalog=School;User ID=sa;Password=842674";
//2创建连接对象
using (SqlConnection con = new SqlConnection(constr))
{
//con.ConnectionString = constr;
//打开连接
con.Open();
//拼接sql语句
string sql = string.Format("insert into class3(cname,cdesc) values('{0}','{1}')", txtClassName.Text.Trim(), txtClassDesc.Text.Trim());
//3创建命令对象
using (SqlCommand cmd = new SqlCommand(sql, con))
{
//cmd.Connection = con;
//cmd.CommandText = sql;
int r = cmd.ExecuteNonQuery();//执行insert,delete ,update正合适
//它的返回值就是执行命令后影响数据表中记录的条数。(正整数0---n)
this.Response.Write("插入"+r+"行");
}
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
//1连接字符串
string constr = "data source=.;initial catalog=School;User ID=sa;Password=842674";
//2创建连接对象
using (SqlConnection con = new SqlConnection(constr))
{
//con.ConnectionString = constr;
//打开连接
con.Open();
//拼接sql语句
string sql = string.Format("delete from class3 where id={0}", txtId.Text.Trim());
//3创建命令对象
using (SqlCommand cmd = new SqlCommand(sql, con))
{
//cmd.Connection = con;
//cmd.CommandText = sql;
int t = cmd.ExecuteNonQuery();//执行insert,delete ,update正合适
//它的返回值就是执行命令后影响数据表中记录的条数。(正整数0---n)
this.Response.Write("删除" + t + "行。");
}
}
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
//1连接字符串
string constr = "data source=.;initial catalog=School;User ID=sa;Password=842674";
//2创建连接对象
using (SqlConnection con = new SqlConnection(constr))
{
//con.ConnectionString = constr;
//打开连接
//拼接sql语句
string sql = string.Format("update class3 set cname='{0}',cdesc='{1}' where id={2}", txtUpdateCname.Text.Trim(), txtUpdateCdesc.Text.Trim(), txtUpdateId.Text.Trim());
//3创建命令对象
using (SqlCommand cmd = new SqlCommand(sql, con))
{
//cmd.Connection = con;
//cmd.CommandText = sql;
con.Open();//
int t = cmd.ExecuteNonQuery();//执行insert,delete ,update正合适
//它的返回值就是执行命令后影响数据表中记录的条数。(正整数0---n)
this.Response.Write("修改了" + t + "行。");
}
}
}
}
}
- insert update delete Table.aspx.cs
- MySQL数据库之INSERT,REPLACE,UPDATE ,DELETE,TRUNCATE TABLE
- Insert Update Delete Select
- Insert , Update , Delete 触发器
- Insert,Update,Delete操作
- insert、delete、update、replace
- INSERT,UPDATE,DELETE时不写日志
- SSIS 实现update,delete,insert
- 數據庫訪問類(Query,Insert,Update,Delete)
- returning into(update,delete,insert)
- LINQ Insert/Update/Delete操作
- SqlServer Trigger insert update delete
- MyBatis-insert, update and delete
- insert、update、delete的用法
- mysql学习-update, delete,insert
- MYSQL INSERT UPDATE DELETE 语句
- SQL INSERT TO &UPDATE&DELETE
- Mysql之insert,update,delete
- 机房收费系统的初步尝试——导入数据库文件
- CenOS U盘安装
- Java学习笔记(六)
- Linux 编译报错 -- undefined reference to 问题解决方法 (具体'pthread_create'和opencv看文章最后两条)
- 基于JRTPLIB库的RTP数据传输设计文档
- insert update delete Table.aspx.cs
- 解决制作交叉编译工具链时报错“/libgcc.mvars: No such file or directory make”
- 演示小程序
- 2012-11-16(selectAll.aspx.cs)
- Java学习笔记(七)
- arm_裸奔
- Android制作自适应图片9.png
- 交换方法
- 原来用循环链表写的现在用数组写(删除数据的,我找到了一个规律)