Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
protected void Stor_Click(object sender, EventArgs e)
    {
        string s1 = "p1";
        DataTable dt = new DataTable();
        dt.Columns.Add("UID");
        dt.Columns.Add("Name");
       
        con.Open();
        foreach (GridViewRow item in GridView1.Rows)
        {
            if ((item.Cells[0].FindControl("CheckBox1") as CheckBox).Checked)
            {
                DataRow dr = dt.NewRow();
                dr["UID"] = item.Cells[0].Text;
                dr["Name"] = item.Cells[1].Text;
                dt.Rows.Add(dr);
                Response.Write(dr["UID"].ToString());
                Response.Write(dr["Name"].ToString());
                int t1 = Convert.ToInt32(dr["UID"].ToString());
                string query = "Update Attendence1 set Status='" + s1 + "' where UID=" + t1 + "";
                SqlCommand cmd = new SqlCommand(query, con);
                cmd.ExecuteNonQuery();
               
            }
        }
        
        
    }


ms sql server
table name Attendence1
UID int
Name nvarchar(50)
Status nvarchar(50)
Posted
Updated 2-Apr-17 20:21pm
v3
Comments
deepankarbhatnagar 11-Mar-15 2:52am    
please check your table name 'Attendence1' as it doesnot recognised thats why error occured.

First of all - NEVER! use string concatenation to create queries. It opens your system to SQL injection attacks...
Use only parametrized queries[^]...
As for the error - it is obvious that there is no such table Attendence1...Check your database...
 
Share this answer
 
Comments
Member 10234718 11-Mar-15 3:16am    
yes there is Attendence1 table
Kornfeld Eliyahu Peter 11-Mar-15 3:19am    
You can argue with me or anyone else, that will not help you. SQL clearly states the there is NO such table, and in this case the only opinion counts is SQL's, so go and convince it!
phil.o 11-Mar-15 8:28am    
You made my day with this one :)
Member 10234718 17-Jun-15 11:21am    
ok
Check that the table Attendence1 is exists in the database which you mentioned in your connection string...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900