Professional Documents
Culture Documents
{
public partial class Form2 : Form
{
SqlConnection con = new SqlConnection("Data Source = ASUS-X555; Initial
Catalog=db_exercisebatch4;Integrated Security=True");
SqlCommand cmd;
SqlDataAdapter adapt;
public Form2()
{
InitializeComponent();
DisplayData();
}
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record Inserted Successfully");
DisplayData();
ClearData();
}
else
{
MessageBox.Show("Please Provide Details!");
}
}
private void DisplayData()
{
con.Open();
DataTable dt = new DataTable();
adapt = new SqlDataAdapter("select * from tb_author", con);
adapt.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}
//Clear Data
private void ClearData()
{
txt_id.Text = "";
txt_authorname.Text = "";
txt_gender.Text = "";
}
private void dataGridView1_RowHeaderMouseClick(object sender,
DataGridViewCellMouseEventArgs e)
{
txt_id.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
txt_authorname.Text =
dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
txt_gender.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();