i am getting an error in btnsave_Click event that object refrence not set to instance of an object i have created an instance still the error prompts
can anyone please suggest possible solution for this
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace WindowsFormsApplication12
{
public partial class Form1 : Form
{
MySqlConnection conn;
DataTable dt;
DataSet ds;
MySqlCommandBuilder builder;
MySqlDataAdapter adp;
DataRow row;
public Form1()
{
InitializeComponent();
}
protected void btnshow_Click(object sender, EventArgs e)
{
conn = new MySqlConnection(@"server=localhost;User Id=root;database=employee");
conn.Open();
adp = new MySqlDataAdapter("select * from employee", conn);
builder = new MySqlCommandBuilder(adp);
ds = new DataSet();
adp.Fill (ds, "employee");
dt = ds.Tables[0];
DataRow dr = dt.Rows[0];
textBox1.Text = dr[0].ToString();
textBox2.Text = dr[1].ToString();
textBox3.Text = dr[2].ToString();
textBox4.Text = dr[3].ToString();
textBox5.Text = dr[4].ToString();
textBox6.Text = dr[5].ToString();
}
protected void btnsave_Click(object sender, EventArgs e) {
DataRow dr = dt.NewRow(); dr[0] = textBox1.Text;
dr[1] = textBox2.Text;
dr[2] = textBox3.Text;
dr[3] = textBox4.Text;
dr[4] = textBox5.Text;
dr[5] = textBox6.Text;
dt.Rows.Add(dr);
adp.Update(ds, "employee");
}
}
}
-