日期:2014-05-19  浏览次数:20896 次

sql语句执行问题
int   selRows   =   0;
               
                SqlConnection   scn   =   new   SqlConnection( "Server=tony-119;Database=login;Integrated   Security=SSPI ");
               
                SqlCommand   scd   =   new   SqlCommand( "select   count(*)   from   [login_1]   where   userName   =@name   and   userPwd   =@pwd ",   scn);
                scd.Parameters.Add(new   SqlParameter( "@name ",Request[ "txtName "].Trim()));
                scd.Parameters.Add(new   SqlParameter( "@pwd ",Request[ "txtPwd "].Trim()));

                try
                {
                        scn.Open();
                        selRows   =   Convert.ToInt32(scd.ExecuteScalar());
                }
                catch   (Exception   ex)
                {
                        Response.Write( "查询语句执行出错 "+ex.ToString());
                        return;
                }
                finally
                {
                        scn.Close();
                }

以上代码执行时抛出异常,提示:System.Data.SqlClient.SqlException:   对象名   'login_1 '   无效

可是,我把SQL语句在查询分析器中执行的时候没有问题。。。

为什么会这样呢?谢谢各位先

------解决方案--------------------
你确定login 库里有login_1这个表?