umair mohsin

umair mohsin

  • 1.4k
  • 387
  • 65.9k

reocrd is not inserted in gridview

Feb 8 2015 12:23 AM
i am having an issue in inserting record in gridview and show it when application runs.  i am  using executenonquery() method .my code is below.
protected void Page_Load(object sender, EventArgs e)
{
string select = "select * from student_table";
string cs = ConfigurationManager.ConnectionStrings["Database1ConnectionString1"].ConnectionString.ToString();
SqlConnection conn = new SqlConnection(cs);
conn.Open();
SqlCommand cmd = new SqlCommand("insert into student_table (id,name,class) values(1,'danish qamar',6)"+select ,conn);
cmd.CommandType = CommandType.Text;

GridView1.DataSource = cmd.ExecuteNonQuery();
GridView1.DataBind();
conn.Close();

}

by using above code record is inserting in the database but not displaying when application run
i got following error:
Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource.
help me to solve it please.

Answers (5)