Library Management System

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

(ADD BOOKS CODES)

Int64 Books;
int BookID;

public View_Book()
{
InitializeComponent();
}

private void View_Book_Load(object sender, EventArgs e)


{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=LAPTOP-OPF1TKLK\\
SQLEXPRESS;Initial Catalog=ViewBooks;Integrated Security=True";
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "Select * from Books where BookID=" + BookID+ "";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);

dataGridView1.DataSource = ds.Tables[0];

private void button1_Click(object sender, EventArgs e)


{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=LAPTOP-OPF1TKLK\\
SQLEXPRESS;Initial Catalog=ViewBooks;Integrated Security=True";
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
conn.Open();
cmd.CommandText = "Insert Into
Books(BookName,BookAuthor,BookPublication,BooKPurchasedDate,BookPrice)values('" +
txt1.Text + "','" + txt2.Text + "','" + txt3.Text + "','" + txt4.Text + "','" +
txt5.Text +"')";

conn.Close();

MessageBox.Show("The Data is succefully added ", "Successfully",


MessageBoxButtons.OK,
MessageBoxIcon.Information);

// show in datagrid
cmd.CommandText = "Select * from Books";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);

dataGridView1.DataSource = ds.Tables[0];
}
private void dataGridView1_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
{
BookID =
int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());

// to show data in message box


//
MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
}
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=LAPTOP-OPF1TKLK\\
SQLEXPRESS;Initial Catalog=ViewBooks;Integrated Security=True";
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "Select * from Books where BookID=" + BookID + "";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
Books = Int64.Parse(ds.Tables[0].Rows[0][0].ToString());
txt1.Text = ds.Tables[0].Rows[0][1].ToString();
txt2.Text = ds.Tables[0].Rows[0][2].ToString();
txt3.Text = ds.Tables[0].Rows[0][3].ToString();
txt4.Text = ds.Tables[0].Rows[0][4].ToString();
txt5.Text = ds.Tables[0].Rows[0][5].ToString();
da.Fill(ds);

(BORROWED BOOKS CODES)

Int64 tableIssue;
int Student_ID;

private void Form1_Load(object sender, EventArgs e)


{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=LAPTOP-OPF1TKLK\\
SQLEXPRESS;Initial Catalog=IssueBooks;Integrated Security=True";
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "Select * from tableIssue where Student_ID=" +
Student_ID+ "";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);

dataGridView1.DataSource = ds.Tables[0];

private void dataGridView1_CellContentClick(object sender,


DataGridViewCellEventArgs e)
{
if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
{
Student_ID =
int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());

// to show data in message box


//
MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
}
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=LAPTOP-OPF1TKLK\\
SQLEXPRESS;Initial Catalog=IssueBooks;Integrated Security=True";
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "Select * from tableIssue where Student_ID=" +
Student_ID + "";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
tableIssue = Int64.Parse(ds.Tables[0].Rows[0][0].ToString());
txt1.Text = ds.Tables[0].Rows[0][1].ToString();
txt2.Text = ds.Tables[0].Rows[0][2].ToString();
txt3.Text = ds.Tables[0].Rows[0][3].ToString();
cmb1.Text = ds.Tables[0].Rows[0][4].ToString();

da.Fill(ds);

private void button1_Click(object sender, EventArgs e)


{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=LAPTOP-OPF1TKLK\\
SQLEXPRESS;Initial Catalog=IssueBooks;Integrated Security=True";
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
conn.Open();
cmd.CommandText = "Insert into tableIssue
(Student_ID,Student_Name,Student_Course,Student_Year,Books_name, Date_issue,
Date_Return)values('" + txt1.Text + "','" + txt2.Text + "','" + txt3.Text + "','" +
cmb1.Text + "','" + "')";

conn.Close();

MessageBox.Show("The Data is succefully added ", "Successfully",


MessageBoxButtons.OK,
MessageBoxIcon.Information);

// show in datagrid
cmd.CommandText = "Select * from tableIssue";
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);

dataGridView1.DataSource = ds.Tables[0];
}
}
}
aA

You might also like