This is my code:
protected void txtcmd_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ConnectionString);
SqlCommand cmd = new SqlCommand();
int ID = int.Parse(Session["Id"].ToString());
string comments = ((TextBox)statusgrdview.FindControl("txtcommt")).Text;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into TBL_Comments(ID,comments) " + "values("+ID+",@comments);" + "select * from TBL_Comments";
cmd.Parameters.Add("@comments", SqlDbType.VarChar).Value = comments;
statusgrdview.DataSource = GetData(cmd);
statusgrdview.DataBind();
}
private object GetData(SqlCommand cmd)
{
throw new NotImplementedException();
}


Dipankar BiswasRank #992 · 2K reputationPosted May 4, 2015, 1:58 AM EDT
I think
SqlCommand cmd= new SqlCommand(con);
Try it..
Deepak Ratan175 reputationPosted May 4, 2015, 2:02 AM EDT
ERROR
Sanjeeb LenkaRank #301 · 8.3K reputationPosted May 4, 2015, 2:04 AM EDT
Deepak Ratan175 reputationPosted May 4, 2015, 2:06 AM EDT
int ID = int.Parse(Session["Id"].ToString());
Akhil GargRank #772 · 3K reputationPosted May 4, 2015, 2:43 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted May 4, 2015, 2:46 AM EDT