Tuesday, 27 November 2012

Blood Bank Using Databse in Windoes Application

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.OleDb;

namespace examblood
{
public partial class Form1 : Form
{
int i = -1;
OleDbConnection con = new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();
OleDbDataReader dr;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
con.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;data source=E:\\blood1.mdb";
con.Open();
cmd.CommandText = "select bgroup from blood1";
cmd.Connection = con;
dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr.GetString(0));

}
//dr.Close();
con.Close();
/* con.Open();
cmd.CommandText = "select * from blood1";
cmd.Connection = con;
dr = cmd.ExecuteReader();
while (dr.Read())
{
i++;
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[0].Value = dr.GetInt16(0);
dataGridView1.Rows[i].Cells[1].Value = dr.GetString(1);
dataGridView1.Rows[i].Cells[2].Value = dr.GetInt16(2);
dataGridView1.Rows[i].Cells[3].Value = dr.GetString(3);
}
con.Close();*/
}

private void button1_Click(object sender, EventArgs e)
{

con.Open();

cmd.CommandText = "insert into blood1 values('" + textBox4.Text + "','" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
cmd.Connection = con;
dr = cmd.ExecuteReader();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
con.Close();

}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//con.Open();
// cmd.CommandText
string s = comboBox1.SelectedItem.ToString();
textBox5.Text = s.ToString();
con.Open();
cmd.CommandText = "select * from blood1 where bgroup='"+s+"'";
cmd.Connection = con;
dr = cmd.ExecuteReader();
while (dr.Read())
{
i++;
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[0].Value = dr.GetInt16(0);
dataGridView1.Rows[i].Cells[1].Value = dr.GetString(1);
dataGridView1.Rows[i].Cells[2].Value = dr.GetInt16(2);
dataGridView1.Rows[i].Cells[3].Value = dr.GetString(3);
}
con.Close();
}

private void textBox5_TextChanged(object sender, EventArgs e)
{

}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
textBox5.Text = dataGridView1.SelectedCells[0].Value.ToString();

}

private void groupBox1_Enter(object sender, EventArgs e)
{

}
}
}

No comments:

Post a Comment