using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 测试
{
public partial class Form1 : Form
{
private DataTable dt = new DataTable();
private SqlDataAdapter sda = new SqlDataAdapter();
private Boolean isUpdate = false;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (isUpdate)
{
try
{
SqlCommandBuilder scb = new SqlCommandBuilder(sda);
sda.Update(dt);
isUpdate = false;
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
MessageBox.Show("更新成功!");
}
else
{
MessageBox.Show("没有更新内容!");
}
for (int i = 0; i < dt.Rows.Count; i++)
for (int j = 0; j < dt.Columns.Count; j++)
{
dataGridView1[j, i].Style.BackColor = Color.Wheat;
}
}
private void Form1_Load(object sender, EventArgs e)
{
load();
}
private void load()
{
string a = this.textBox1.Text;
string str = "Uid=sa;pwd=fy%%8212733;database=hisdata;server=192.168.16.251";
SqlConnection conn = new SqlConnection(str);
SqlCommand scd = new SqlCommand("select zyh 住院号,zyid 住院ID, xm 姓名,rysj 入院时间,cysj 出院时间 from zy_brxx where zyh ='"+ a +"'", conn);
sda.SelectCommand = scd;
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
isUpdate = true;
dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Blue;
}
private void button2_Click(object sender, EventArgs e)
{
string a = this.textBox1.Text;
if (a.Equals(""))
{
MessageBox.Show("住院号不能为空");
}
else
{
string str = "Uid=sa;pwd=fy%%8212733;database=hisdata;server=192.168.16.251";
SqlConnection conn = new SqlConnection(str);
SqlCommand scd = new SqlCommand("select zyh 住院号,zyid 住院ID, xm 姓名,rysj 入院时间,cysj 出院时间 from zy_brxx where zyh ='" + a + "'", conn);
sda.SelectCommand = scd;
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 测试
{
public partial class Form1 : Form
{
private DataTable dt = new DataTable();
private SqlDataAdapter sda = new SqlDataAdapter();
private Boolean isUpdate = false;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (isUpdate)
{
try
{
SqlCommandBuilder scb = new SqlCommandBuilder(sda);
sda.Update(dt);
isUpdate = false;
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
MessageBox.Show("更新成功!");
}
else
{
MessageBox.Show("没有更新内容!");
}
for (int i = 0; i < dt.Rows.Count; i++)
for (int j = 0; j < dt.Columns.Count; j++)
{
dataGridView1[j, i].Style.BackColor = Color.Wheat;
}
}
private void Form1_Load(object sender, EventArgs e)
{
load();
}
private void load()
{
string a = this.textBox1.Text;
string str = "Uid=sa;pwd=fy%%8212733;database=hisdata;server=192.168.16.251";
SqlConnection conn = new SqlConnection(str);
SqlCommand scd = new SqlCommand("select zyh 住院号,zyid 住院ID, xm 姓名,rysj 入院时间,cysj 出院时间 from zy_brxx where zyh ='"+ a +"'", conn);
sda.SelectCommand = scd;
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
isUpdate = true;
dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Blue;
}
private void button2_Click(object sender, EventArgs e)
{
string a = this.textBox1.Text;
if (a.Equals(""))
{
MessageBox.Show("住院号不能为空");
}
else
{
string str = "Uid=sa;pwd=fy%%8212733;database=hisdata;server=192.168.16.251";
SqlConnection conn = new SqlConnection(str);
SqlCommand scd = new SqlCommand("select zyh 住院号,zyid 住院ID, xm 姓名,rysj 入院时间,cysj 出院时间 from zy_brxx where zyh ='" + a + "'", conn);
sda.SelectCommand = scd;
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
}
}