急救,请大虾们指教

wctmac 2010-11-15 04:18:11
小弟第一次用存储过程来写程序 是一个登录的页面 但是我运行后却报错 先把代码给贴出来 供大虾们看下

存储过程:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER proc [dbo].[up_SelLog]
as
declare @UserId varchar(50),
@Password varchar(50)
select * from UserInfo where UserId=@UserId and Password=@Password
----------------------------------------------------------------------
数据访问层:
public List<UserInfoInfo> SelLog(string uname, string upwd)
{
string proc = "up_SelLog";
SqlParameter[] parm = new SqlParameter[]{
new SqlParameter("@UserId",uname),
new SqlParameter("@Password",upwd)
};
return getList(getDS("1", proc, parm));
}

public List<UserInfoInfo> getList(System.Data.DataSet ds)
{
List<UserInfoInfo> list = new List<UserInfoInfo>();
foreach (DataRow dr in ds.Tables[0].Rows)
{
UserInfoInfo uii = new UserInfoInfo();
uii.UserId = dr["UserId"].ToString();
uii.Password = dr["Password"].ToString();
list.Add(uii);
}
return list;
}
-----------------------------------------------------------
业务逻辑层:

public Boolean SelLog(string uname, string upwd)
{
bool bl = false;
List<UserInfoInfo> list = iUserInfo.SelLog(uname, upwd);
if (list !=null && list.Count > 0)
{
bl = true;
}
else
{
bl = false;
}
return bl;
}
------------------------------------------------------------
表示层:
protected void Button1_Click(object sender, EventArgs e)
{
UserInfoManager uim = new UserInfoManager();
UserInfoInfo uii = new UserInfoInfo();
bool bl = uim.SelLog(TextBox1.Text.Trim(), TextBox2.Text.Trim());
if (bl)
{
Response.Redirect("WebForm1.aspx");
}
else
{
this.Page.ClientScript.RegisterStartupScript(GetType(),"","<script>alert('用户名或密码错误!');</script>");
}
}
-------------------------------------------------------------
但是当我运行程序后 点击登录按钮就报错,错误是说:‘SelLog’附近有语法错误 请大虾们指教
...全文
137 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
heheerwa 2010-11-25
  • 打赏
  • 举报
回复
同志,这个问题你是解决了,但是你有没想过,你这里存在slq注入?
试想我这么登录
用户名:'' or 1=1
密码也同上~
这样会发生什么事那?
在试想,我做成一个子查询语句,又会怎么样那?
wctmac 2010-11-15
  • 打赏
  • 举报
回复
解决了 dbhelper的问题
liuxueqian307 2010-11-15
  • 打赏
  • 举报
回复
你就去程序调数据库那里找问题吧,就应该在那里,参数出问题的几率很大
wctmac 2010-11-15
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 hookyzlr 的回复:]
单补调试下,看看异常出现在那句话下。
具体是什么错误
[/Quote]
就是在dbheper抛出的错
我的dbheper:
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

namespace CN.ACCP.MyOfficeDAL
{
public class DBHelper
{
#region 读取数据库连接字符串
string constr = string.Empty;

public string Constr
{
get { return ConfigurationManager.ConnectionStrings["con"].ConnectionString; }

}
#endregion

SqlConnection con = new SqlConnection();

#region "打开一个可用的连接"
/// <summary>
/// 打开一个可用的连接
/// </summary>
/// <returns></returns>
public SqlConnection getcon()
{
try
{
con.ConnectionString = this.Constr;
con.Open();
}
catch (Exception ex)
{
throw ex;


}
return con;
}
#endregion

#region "关闭连接"
/// <summary>
/// 关闭连接
/// </summary>
public void CloseDb()
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
#endregion

#region "执行增加、删除、修改"
/// <summary>
/// 执行增加、删除、修改
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="parm">SQL语句参数</param>
/// <returns></returns>
public int ExcuteCommand(string Type, string sql, params SqlParameter[] parm)
{
SqlCommand cmd = getcon().CreateCommand();
if (Type == "0")
{
cmd.CommandType = CommandType.Text;
}
else if (Type == "1")
{
cmd.CommandType = CommandType.StoredProcedure;
}
cmd.CommandText = sql;
//if (parm != null)
//{
// cmd.Parameters.AddRange(parm);
//}
int result = -1;
try
{
result = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{

throw ex;
}
finally
{
cmd.Dispose();
CloseDb();
}
return result;
}
#endregion

#region "执行查询"
/// <summary>
/// 执行查询
/// </summary>
/// <param name="sql">SQL语句</param>
/// <param name="parm">SQL语句参数</param>
/// <returns></returns>
public DataSet getDS(string Type, string sql, params SqlParameter[] parm)
{
SqlDataAdapter sda = new SqlDataAdapter(sql, this.Constr);
DataSet ds = new DataSet();
SqlCommand cmd = getcon().CreateCommand();
if (parm != null)
{
sda.SelectCommand.Parameters.AddRange(parm);
}
if (Type == "0")
{
cmd.CommandType = CommandType.Text;
}
else if (Type == "1")
{
cmd.CommandType = CommandType.StoredProcedure;
}

try
{
sda.Fill(ds);
}
catch (Exception ex)
{

throw ex;
}
finally
{
sda.Dispose();
}
return ds;
}
#endregion
}
}

hookyzlr 2010-11-15
  • 打赏
  • 举报
回复
单补调试下,看看异常出现在那句话下。
具体是什么错误
wctmac 2010-11-15
  • 打赏
  • 举报
回复
到底是什么问题,大虾们帮帮忙吧
wctmac 2010-11-15
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 ytmom 的回复:]
额,我第一个贴出来的最顶上的就是存储过程啊 还注明了
[/Quote]
?
ytmom 2010-11-15
  • 打赏
  • 举报
回复


额,我第一个贴出来的最顶上的就是存储过程啊 还注明了
wctmac 2010-11-15
  • 打赏
  • 举报
回复
who can help me 3Q
wctmac 2010-11-15
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 hookyzlr 的回复:]
存储过程定义问题,改成:
ALTER proc [dbo].[up_SelLog] (@UserId varchar(50),@Password varchar(50))
as
select * from UserInfo where UserId=@UserId and Password=@Password
[/Quote]
我不是也定义了变量了嘛,ALTER proc [dbo].[up_SelLog]
as
declare @UserId varchar(50),
@Password varchar(50)
我用了你这种方法还是报我这个错误ALTER proc [dbo].[up_SelLog] (@UserId varchar(50),@Password varchar(50))
hookyzlr 2010-11-15
  • 打赏
  • 举报
回复
因为你在数据层是给存储过程传的参数。
而你的存储过程却没有参数。
hookyzlr 2010-11-15
  • 打赏
  • 举报
回复
存储过程定义问题,改成:
ALTER proc [dbo].[up_SelLog] (@UserId varchar(50),@Password varchar(50))
as
select * from UserInfo where UserId=@UserId and Password=@Password
wctmac 2010-11-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 biaofanwo 的回复:]
存储过程呢?
[/Quote]
额,我第一个贴出来的最顶上的就是存储过程啊 还注明了
biaofanwo 2010-11-15
  • 打赏
  • 举报
回复
存储过程呢?
wctmac 2010-11-15
  • 打赏
  • 举报
回复
少写了 ,报错的是说:‘up_SelLog’附近有语法错误,是不是数据访问层的参数parm那个我写的不对啊,以前我不用存储过程的话,@userId,@Password都是有的,现在用了存储过程,这个到村纯过程去了,那我业务逻辑层还是写着两个,又没定义 是不是就这么报错了,应该如何改呢

62,272

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧