断开式访问数据库

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp10
{
    public partial class Form1 : Form
    {
        string conStr = "Data Source=(local);Initial Catalog=db_student;Integrated Security=True;";
        SqlConnection con = null;
        SqlDataAdapter da = null;
        DataSet ds = null;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            con = new SqlConnection(conStr);
            da = new SqlDataAdapter("select * from studentscore", con);
            ds = new DataSet();
            da.Fill(ds, "studentscore");
            dataGridView1.DataSource = ds.Tables["studentscore"];
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            txtNum.Text = dataGridView1.CurrentRow.Cells["num"].Value.ToString();
            txtName.Text = dataGridView1.CurrentRow.Cells["name"].Value.ToString();
            txtScore.Text = dataGridView1.CurrentRow.Cells["score"].Value.ToString();

        }

        private void btnselect_Click(object sender, EventArgs e)
        {
            SqlCommandBuilder builder = new SqlCommandBuilder(da);
            DataRow r1 = ds.Tables["studentscore"].NewRow();
            r1[0] = txtNum.Text;
            r1[1] = txtName.Text;
            r1[2] = txtScore.Text;
            ds.Tables[0].Rows.Add(r1);
            da.Update(ds, "studentscore");
            dataGridView1.DataSource = ds.Tables["studentscore"];
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            SqlCommandBuilder builder= new SqlCommandBuilder(da);
            DataRowCollection rows = ds.Tables["studentscore"].Rows;
            DataRow row;
            for(int i = 0; i < rows.Count; i++)
            {
                row = rows[i];
                if (row["num"].ToString()==txtNum.Text)
                {
                    row["score"]=txtScore.Text;
                    row["name"] = txtName.Text;
                }
            }
            dataGridView1.DataSource = ds.Tables["studentscore"];
            da.Update(ds, "studentscore");
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            SqlCommandBuilder builder=new SqlCommandBuilder(da);
            DataRowCollection rows = ds.Tables["studentscore"].Rows;
            DataRow row;
            for (int i = 0;i < rows.Count;i++)
            {
                row = rows[i];
                if (row["num"].ToString()==txtNum.Text)
                {
                    row.Delete();
                }
            }
            da.Update(ds, "studentscore");
            dataGridView1.DataSource = ds.Tables["studentscore"];
        }
    }


    public class User {
        private string name;
        private string pwd;
        private int role;
        public string Name {
            get { return name;}
            set { name = value; }
        }
        public string Pwd
        {
            get { return pwd; }
            set { pwd = value; }
        }
        public int Role
        {
            get { return role; }
            set { role = value; }
        }
        public User()
        {
            name = "";
            pwd = "";
            role = 0;
        }
        public User(string _name,string _pwd,int _role)
        {
            name = _name;
            pwd = _pwd;
            role = _role;
        }
    }

    public class RoomInfo {

        private string roomId;
        private string roomType;
        private string roomFloor;
        private double price;
        private int personNum;
        private int inPerson;
        private string note;
        public string RoomId {
            get { return roomId; }
            set { roomId = value; }
        }
        public string RoomType
        {
            get { return roomType; }
            set { roomType = value; }
        }
        public string RoomFloor
        {
            get { return roomFloor; }
            set { roomFloor = value; }
        }
        public double Price
        {
            get { return price; }
            set { price = value; }
        }
        public int PersonNum
        {
            get { return personNum; }
            set { personNum = value; }
        }
        public int InPerson
        {
            get { return inPerson; }
            set { inPerson = value; }
        }
        public string Note
        {
            get { return note; }
            set { note = value; }
        }
    
    
    
    
    }

    public class CheckInRoom {

        private int inId;
        private string roomId;
        private double price;
        private double foregift;
        private DateTime inTime;
        private DateTime outTime;
        private string clientName;
        private bool sex;
        private string phone;
        private string certType;
        private string certId;
        private string address;
        private string oper;
        private int personNum;
        private int delMark;
        public int InId{
            get { return inId; }
            set { inId = value; }
        }
        public string RoomId
        {
            get { return roomId; }
            set { roomId = value; }
        }
        public double Price
        {
            get { return price; }
            set { price= value; }
        }
        public double Foregift
        {
            get { return foregift; }
            set { foregift = value; }
        }
        public DateTime InTime
        {
            get { return inTime; }
            set { inTime = value; }
        }
        public DateTime OutTime
        {
            get { return outTime; }
            set { outTime = value; }
        }
        public string ClientName
        {
            get { return clientName; }
            set { clientName = value; }
        }
        public bool Sex
        {
            get { return sex; }
            set { sex = value; }
        }
        public string Phone
        {
            get { return phone; }
            set { phone = value; }
        }
        public string CertType
        {
            get { return certType; }
            set { certType = value; }
        }
        public string CertId
        {
            get { return certId; }
            set { certId = value; }
        }
        public string Address
        {
            get { return address; }
            set { address= value; }
        }
        public int PersonNum
        {
            get { return personNum; }
            set { personNum= value; }
        }
        public string Oper
        {
            get { return oper; }
            set { oper = value; }
        }
        public int DelMark
        {
            get { return delMark; }
            set { delMark = value; }
        }

        
        
        
        
    
    }

}
 

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Emo怀秋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值