📄 添加病人.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class 添加病人 : Form
{
SqlCommand cmd;
SqlDataReader dr;
SqlConnection cn = new SqlConnection();
public 添加病人()
{
InitializeComponent();
}
private void Form10_Load(object sender, EventArgs e)
{
int num=1;
cn.ConnectionString = "Data Source=sclab76\\SQLEXPRESS;Initial Catalog=医院管理系统;User id=sa;Password=niit#1234";
cn.Open();
cmd = new SqlCommand("Select OPID from Patient", cn);
dr = cmd.ExecuteReader();
while (dr.Read())
{
num += 1;
}
label6.Text = "000" + num.ToString();
cn.Close();
cn.Open();
cmd = new SqlCommand("Select Insurance_Type from Insurance", cn);
dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr["Insurance_Type"].ToString());
}
cn.Close();
}
private void btn_cancle_Click(object sender, EventArgs e)
{
this.Close();
}
private void btn_con_Click(object sender, EventArgs e)
{
cn.ConnectionString = "Data Source=sclab76\\SQLEXPRESS;Initial Catalog=医院管理系统;User id=sa;Password=niit#1234";
cn.Open();
SqlTransaction tran = null;
try
{
tran = cn.BeginTransaction();
SqlCommand cmd = new SqlCommand("insert into Patient(OPID,Name,Address,Insuranve_Type,Password)values(@opid,@name,@address,@intype,@password)", cn, tran);
cmd.Parameters.Add(new SqlParameter("@opid", label6.Text));
cmd.Parameters.Add(new SqlParameter("@name", txt_name.Text));
cmd.Parameters.Add(new SqlParameter("@address", txt_address.Text));
cmd.Parameters.Add(new SqlParameter("@intype", Convert.ToInt32(comboBox1.Text)));
cmd.Parameters.Add(new SqlParameter("@password", txt_password.Text));
cmd.ExecuteNonQuery();
tran.Commit();
MessageBox.Show("更新成功");
}
catch (SqlException ex)
{
tran.Rollback();
MessageBox.Show(ex.Message);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cn.Close();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -