C#,APS.net三层架构错误。用户代码未处理sqlexception,关键字User附近有错误
publicclassDA{//声明对象staticSqlConnectionconn;staticSqlCommandcmd;staticSqlDataAdapters...
public class DA
{
//声明对象
static SqlConnection conn;
static SqlCommand cmd;
static SqlDataAdapter sda;
static DataSet ds;
//sqldatareader,用别的来替换,多行使用数据集
static DA()
{
conn = new SqlConnection(@"server=.\sqlexpress;database=Travel;integrated security=sspi");
//conn = new SqlConnection(ConfigurationManager.ConnectionStrings["OrderconnString"].ConnectionString);
cmd = new SqlCommand();
cmd.Connection = conn;
}
Business层的方法是这样的
public int UserLogin(int uno,string upwd)
{
string sqlText = "select count(*) from User where uno=@uno8 and upwd=@upwd";
string[] paraNames = { "@uno8", "@upwd" };
object[] paraValues = { uno, upwd };
int i =Convert.ToInt32( DA.GetOneData(sqlText, CommandType.Text, paraNames, paraValues));
return i;
} 展开
{
//声明对象
static SqlConnection conn;
static SqlCommand cmd;
static SqlDataAdapter sda;
static DataSet ds;
//sqldatareader,用别的来替换,多行使用数据集
static DA()
{
conn = new SqlConnection(@"server=.\sqlexpress;database=Travel;integrated security=sspi");
//conn = new SqlConnection(ConfigurationManager.ConnectionStrings["OrderconnString"].ConnectionString);
cmd = new SqlCommand();
cmd.Connection = conn;
}
Business层的方法是这样的
public int UserLogin(int uno,string upwd)
{
string sqlText = "select count(*) from User where uno=@uno8 and upwd=@upwd";
string[] paraNames = { "@uno8", "@upwd" };
object[] paraValues = { uno, upwd };
int i =Convert.ToInt32( DA.GetOneData(sqlText, CommandType.Text, paraNames, paraValues));
return i;
} 展开
1个回答
展开全部
select count(*) from User
语句问题
不能用 count(*) ,后面的参数会找不到列 uno upwd
语句问题
不能用 count(*) ,后面的参数会找不到列 uno upwd
追问
改成select * from User 也不行
追答
SqlParameter[] parameters = {
new SqlParameter("@uno8", DbType.Int32),
new SqlParameter("@upwd", DbType.String),
parameters[0].Value = uno;
parameters[1].Value = upwd;
把类型定义下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询