1. Abdullah | 201003 | Lab Task 10
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace Lab_10
{
public partial class Form1 : Form
{
string connectionstring = @"server = localhost; database = db_book; uid = root; pwd =
root";
int book_id;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
2. }
private void label1_Click(object sender, EventArgs e)
{
}
private void btn_save_Click(object sender, EventArgs e)
{
using (MySqlConnection con = new MySqlConnection(connectionstring))
{
con.Open();
using(MySqlCommand com = new MySqlCommand("insert into tbl_book(book_id,
book_name, book_auther, book_description)" +
"values(@book_id,@book_name, @book_auther, @book_description)", con))
{
com.Parameters.AddWithValue("@book_id", book_id);
com.Parameters.AddWithValue("@book_name", book_name.Text.Trim());
com.Parameters.AddWithValue("@book_auther", Text_Author.Text.Trim());
com.Parameters.AddWithValue("@book_description",
Text_Description.Text.Trim());
com.ExecuteNonQuery();
MessageBox.Show("Record saved SUCCESSFULLY.");
}
}
}
3. private void Text_Name_TextChanged(object sender, EventArgs e)
{
}
private void Text_Author_TextChanged(object sender, EventArgs e)
{
}
private void Text_Description_TextChanged(object sender, EventArgs e)
{
}
private void btn_display_Click(object sender, EventArgs e)
{
using (MySqlConnection con = new MySqlConnection(connectionstring))
{
con.Open();
MySqlDataAdapter da = new MySqlDataAdapter("Select * from tbl_book", con);
DataTable dt = new DataTable();
da.Fill(dt);
dgv1.DataSource = dt;
}