title: CommandText property has not been initialized error in gridview
body: <p>I have a gridview and I want to checked line in insert but I see this error:</p>
  
  <blockquote>
    <p>CommandText property has not been initialized.</p>
  </blockquote>
  
  <p>I guess my mistake about strArrays. I'm working two days about it</p>
  
  <p>How can I fixed?</p>
  
  <pre><code>StringBuilder stringBuilder = new StringBuilder(string.Empty);
  SqlConnection sqlConnection = new  SqlConnection(ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString.ToString());
  SqlCommand sqlCommand = new SqlCommand();
  for (int i = 0; i &lt; GridView1.Rows.Count; i++)
  {
     int type = 2;
     CheckBox chkUpdate = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chkSelect");
  
     TextBox txtAmount = (TextBox)GridView1.Rows[i].Cells[5].FindControl("txtAmount");
  
     if (chkUpdate != null)
     {
        if (chkUpdate.Checked)
        {
           string strID = GridView1.Rows[i].Cells[1].Text;
           GridView1.Rows[i].FindControl("txtLocation")).Text;
           string text = this.GridView1.Rows[i].Cells[1].Text;
           string[] strArrays = new string[] { "INSERT INTO [OrderCancel]
                                               ([OrderID], 
                                                [Message], 
                                                [Type],
                                                [RelationProductID],
                                                [Amount]) 
                                                VALUES(" , 
                                                Request.QueryString["o"] ,
                                                ",'" , txtWhy.Text , 
                                                "',",type.ToString(),",
                                                " , strID , "," , 
                                                txtAmount.Text , ");" };
           stringBuilder.Append(string.Concat(strArrays));
  
           //append update statement in stringBuilder 
           stringBuilder.Append(string.Concat(strArrays));
        }
     }
     try
     {
        try
        {
           sqlCommand.CommandType = CommandType.Text;
           sqlCommand.CommandText = stringBuilder.ToString();
           sqlCommand.Connection = sqlConnection;
           sqlConnection.Open();
           sqlCommand.ExecuteNonQuery();
        }
        catch (SqlException sqlException)
        {
           throw new Exception(string.Concat("Error in Updation",
                                              sqlException.Message));
        }
     }
     finally
     {
        sqlConnection.Close();
     }     
  </code></pre>