System.Data.dll中发生类型'System.Data.SqlClient.SqlException'的异常,但未在用户代码中处理附加信息:无效的对象名称'Attendence1'。 [英] An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code Additional information: Invalid object name 'Attendence1'.

查看:400
本文介绍了System.Data.dll中发生类型'System.Data.SqlClient.SqlException'的异常,但未在用户代码中处理附加信息:无效的对象名称'Attendence1'。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

表名称Attendence1

UID int

名称nvarchar(50)

状态nvarchar(50)



ms sql server
table name Attendence1
UID int
Name nvarchar(50)
Status nvarchar(50)

推荐答案

首先 - 永远不要!使用字符串连接来创建查询。它打开你的系统进行SQL注入攻击...

仅使用参数化查询 [ ^ ] ...

至于错误 - 显然没有这样的表Attendence1 ...检查您的数据库。 ..
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...


检查您在连接字符串中提到的数据库中是否存在表Attendence1 ...
Check that the table Attendence1 is exists in the database which you mentioned in your connection string...


这篇关于System.Data.dll中发生类型'System.Data.SqlClient.SqlException'的异常,但未在用户代码中处理附加信息:无效的对象名称'Attendence1'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆