Question : GridView RowUpdating Problem

Hello Experts,
There is a problem on my commandtext string. Because it cannot find TextBox2 object.

Please help...

Regards
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        SqlConnection MyNewConnection3 = new SqlConnection();
        SqlCommand MyNewQuery3 = new SqlCommand();


        MyNewConnection3.ConnectionString = "Data Source=.;Initial Catalog=FOREVER;User ID=sa;Password=1";
        MyNewConnection3.Open();
        MyNewQuery3.Connection = MyNewConnection3;

        


       
        
       


        MyNewQuery3.CommandText = "SET DATEFORMAT DMY UPDATE IAS_ALLOCATIONS" +
                 " SET [AllQty] =" + GridView2.SelectedRow.FindControl("TextBox2").GetType() +
          " WHERE AllocationID='" + GridView1.SelectedRow.Cells[1].Text.Trim() + "' " +
          "AND Barcode='" + GridView2.SelectedRow.Cells[2].Text.Trim() + "' ";


        //SqlCommand cmd = new SqlCommand(strSQL, cn);
        //cmd.CommandTimeout = 0;
        //if (cn.State == ConnectionState.Closed)
        //{
        //    cn.Open();
        //}
        MyNewQuery3.ExecuteNonQuery();
        MyNewConnection3.Close();

    }

Answer : GridView RowUpdating Problem


If [AllQty] is a text column, then you have to place the Text value inside single quotes as below:

Line 20: " SET [AllQty] ='" + ((TextBox)GridView2.SelectedRow.FindControl("TextBox2")).Text + "'" +
Random Solutions  
 
programming4us programming4us