i am creating a simple crud in c#.net.after add the record record will show on the datagridview itself. but i couldn't do it. code which tried so far i attched below.
code
sql = "insert into student(stname,course,fee)values(@stname,@course,@fee)";
con.Open();
cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("@stname", stname);
cmd.Parameters.AddWithValue("@course", course);
cmd.Parameters.AddWithValue("@fee",stfee);
load();
dataGridView1.Update();
dataGridView1.Refresh();
data load to datagridview
public void load()
{
try
{
string sql;
sql = "select * from student";
cmd = new SqlCommand(sql, con);
con.Open();
dr = cmd.ExecuteReader();
dee = new SqlDataAdapter(sql, con);
while (dr.Read())
{
dataGridView1.Rows.Add(dr[0], dr[1], dr[2], dr[3]);
}
con.Close();
}
catch(Exception ex)
{
}
finally
{
con.Close();
cmd.Dispose();
}
}