关于怎么写类

panzi667 2006-04-22 10:06:06
我写咯一个关于登陆的类,但是总是出错,请高手指点

public int ht_login(string username,string userpass,string state)
{
string connectionString = ConfigurationManager.AppSettings["conn"];
using (OleDbConnection connection1 = new OleDbConnection(connectionString))
{
try
{
connection1.Open();
OleDbCommand command1 = new OleDbCommand();
command1.CommandText = "select * from cont_user where user_id=? and user_pwd=? and user_go=?";
OleDbParameter parameter1 = new OleDbParameter("@user_id", OleDbType.LongVarChar, 50);
parameter1.Direction = ParameterDirection.Input;
OleDbParameter parameter2 = new OleDbParameter("@user_pwd", OleDbType.LongVarChar, 50);
parameter2.Direction = ParameterDirection.Input;
OleDbParameter parameter3 = new OleDbParameter("@user_state", OleDbType.LongVarChar, 50);
parameter3.Direction = ParameterDirection.Input;

command1.Parameters.Add(parameter1);
command1.Parameters.Add(parameter2);
command1.Parameters.Add(parameter3);

parameter1.Value = username;
parameter2.Value = userpass;
parameter3.Value = state;

command1.Connection = connection1;
Int32 count = (Int32)command1.ExecuteNonQuery();

return count;

}
catch (Exception ex)
{
string ErrMsg = ex.Message.Replace("\n", "");
connection1.Close();
return -1;
}
}


}
...全文
127 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
panzi667 2006-04-22
  • 打赏
  • 举报
回复
怎么输出?
偶是菜鸟
powerzy 2006-04-22
  • 打赏
  • 举报
回复
你在catch里面把获取到的异常输出来看看
panzi667 2006-04-22
  • 打赏
  • 举报
回复
int count=my_login.ht_login(username,userpass,user_go);
Response.Write(count);

我在登陆的时候调用,但是我输入数据是正确的,他也 return -1;所以我想问问
1,我写的这个类出现什么问题咯
2,我写的这个真的不是类么?如果是类,应该怎么写?
3,假如是类的话,我写的这个登陆类存在什么问题么?


public class mylogin
{
public int ht_login(string username,string userpass,string state)
{
string connectionString = ConfigurationManager.AppSettings["conn"];
using (OleDbConnection connection1 = new OleDbConnection(connectionString))
{
try
{
connection1.Open();
OleDbCommand command1 = new OleDbCommand();
command1.CommandText = "select * from cont_user where user_id=? and user_pwd=? and user_go=?";
OleDbParameter parameter1 = new OleDbParameter("@user_id", OleDbType.LongVarChar, 50);
parameter1.Direction = ParameterDirection.Input;
OleDbParameter parameter2 = new OleDbParameter("@user_pwd", OleDbType.LongVarChar, 50);
parameter2.Direction = ParameterDirection.Input;
OleDbParameter parameter3 = new OleDbParameter("@user_state

", OleDbType.LongVarChar, 50);
parameter3.Direction = ParameterDirection.Input;

command1.Parameters.Add(parameter1);
command1.Parameters.Add(parameter2);
command1.Parameters.Add(parameter3);

parameter1.Value = username;
parameter2.Value = userpass;
parameter3.Value = state;

command1.Connection = connection1;
Int32 count = (Int32)command1.ExecuteNonQuery();

return count;

}
catch (Exception ex)
{
string ErrMsg = ex.Message.Replace("\n", "");
connection1.Close();
return -1;
}
}


}
}
panzi667 2006-04-22
  • 打赏
  • 举报
回复
他总是 return -1;
冬夜紫雨 2006-04-22
  • 打赏
  • 举报
回复

没看到CLASS啊
活靶子哥哥 2006-04-22
  • 打赏
  • 举报
回复
出什么错?
7712190 2006-04-22
  • 打赏
  • 举报
回复
我认为 很少有人把这个称为类
  • 打赏
  • 举报
回复
catch (Exception ex)
{
throw new Exception ex.ToString();
string ErrMsg = ex.Message.Replace("\n", "");
connection1.Close();
return -1;
}

这样就可以看到错误了!

62,046

社区成员

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

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

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

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