基本信息
源码名称:c#实现对sqlsever数据库 增删改查
源码大小:0.38M
文件格式:.rar
开发语言:C#
更新时间:2020-06-02
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

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 ShuJulKu
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //查询数据 表 IDcare  
        protected void Button1_Click(object sender, EventArgs e)
        {
        
            using(SqlConnection con1=new SqlConnection(@"server=192.168.0.153;uid=sa,pwd=123456;database=abc"))
            {
                con1.Open();
                using (SqlCommand com2 = new SqlCommand(@"select   UserLog.ID, UserLog.Type, UserLog.Message, UserLog.Time,
UserInfo.Name from UserInfo inner join 
UserLog on UserInfo.ID = UserLog.UserID where (UserLog.UserID = '{0}') 
order by UserInfo.Name desc, UserLog.Time desc", con1))
                {
                    SqlDataReader read= com2.ExecuteReader();
                    while (read.Read())
                    {
                        TableRow tbrow = new TableRow();
                        for (int i = 0; i < read.FieldCount; i  )
                        {
                            TableCell cell = new TableCell();
                            cell.Text = read[i].ToString();
                            tbrow.Cells.Add(cell);
                        }
                        Table1.Rows.Add(tbrow);
                    }
                }
            }
        }

        //插入数据   添加 10029行
        protected void Button2_Click(object sender, EventArgs e)
        {
            using (SqlConnection con = new SqlConnection(@"data source=Z-PC15\SQLEXPRESS;Initial Catalog=abc;Integrated security=true "))
            {
                con.Open();
                using (SqlCommand com = new SqlCommand("insert into IDcare values('10029','2017-12-3',3450,3)", con))
                {
                    int a = com.ExecuteNonQuery();
                    TextBox1.Text = "插入"   a   "条记录成功!!!!";
                }
            }
        }

        //修改数据   修改10029行 为10030行
        protected void Button3_Click(object sender, EventArgs e)
        {
            using (SqlConnection con2 = new SqlConnection(@"data source=Z-PC15\SQLEXPRESS;Initial Catalog=abc;Integrated security=true"))
            {
                con2.Open();
                string st = "update  IDcare set vID=10030,mtime='2015-12-12',mony=100,times=10  where vID=10029";
                SqlCommand com2 = new SqlCommand(st, con2);
                int b = com2.ExecuteNonQuery();
                TextBox1.Text = "修改"   b   "条记录成功!!!!!";
            }
        }

        //删除数据   删除10030行
        protected void Button4_Click(object sender, EventArgs e)
        {
            using (SqlConnection con3 = new SqlConnection(@"data source=Z-PC15\SQLEXPRESS;Initial Catalog=abc;Integrated security=true"))
            {
                con3.Open();
                SqlCommand com3 = new SqlCommand("delete from IDcare where  vID='10030'  ", con3);
                int c = com3.ExecuteNonQuery();
                TextBox1.Text = "删除"   c   "条记录成功!!!!";
            }
        }





    }
}