public class DataBase
{
public DataBase()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//string strCon = "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=TestOnline";
private SqlConnection SqlCon = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=TestOnline");
private SqlCommand SqlCmd;
// private SqlDataAdapter da;
// private DataSet ds; public int GetUser(string ComStr)
{
SqlCon.Open();
SqlCmd = new SqlCommand(ComStr, SqlCon);
int i;
i = Convert.ToInt32(SqlCmd.ExecuteScalar());
return i;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
DataBase db = new DataBase(); if (this.TextBox1.Text.Trim() == "" || this.TextBox2.Text.Trim() == "" || this.DropDownList1.SelectedValue == "")
{
Response.Write("<script>alert(\"账号,密码,用户类型不能为空\");</script>");
}
else
{
switch (DropDownList1.SelectedValue)
{
case "学生":
string SelCmd = "SELECT COUNT(*) FROM Student WHERE Name=" + this.TextBox1.Text + "and Pwd='" + this.TextBox2.Text + "'";
// int tmp = db.GetUser(SelCmd);
// Response.Write(tmp.GetType());
if (db.GetUser(SelCmd) != 0) //System.Data.SqlClient.SqlException: 将数据类型 varchar 转换为 numeric 时出错。
{
Session["StuNo"] = this.TextBox1.Text;
Response.Write("<script>alert(\"登陆成功\");</script>");
}
else
{
Response.Write("<script>alert(\"账号或密码错误\");<script>");
}
break;
default:
// Session["StuNo"] = this.TextBox1.Text;
// Response.Write(Session.ToString());
break;
}
}
}
{
public DataBase()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//string strCon = "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=TestOnline";
private SqlConnection SqlCon = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=TestOnline");
private SqlCommand SqlCmd;
// private SqlDataAdapter da;
// private DataSet ds; public int GetUser(string ComStr)
{
SqlCon.Open();
SqlCmd = new SqlCommand(ComStr, SqlCon);
int i;
i = Convert.ToInt32(SqlCmd.ExecuteScalar());
return i;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
DataBase db = new DataBase(); if (this.TextBox1.Text.Trim() == "" || this.TextBox2.Text.Trim() == "" || this.DropDownList1.SelectedValue == "")
{
Response.Write("<script>alert(\"账号,密码,用户类型不能为空\");</script>");
}
else
{
switch (DropDownList1.SelectedValue)
{
case "学生":
string SelCmd = "SELECT COUNT(*) FROM Student WHERE Name=" + this.TextBox1.Text + "and Pwd='" + this.TextBox2.Text + "'";
// int tmp = db.GetUser(SelCmd);
// Response.Write(tmp.GetType());
if (db.GetUser(SelCmd) != 0) //System.Data.SqlClient.SqlException: 将数据类型 varchar 转换为 numeric 时出错。
{
Session["StuNo"] = this.TextBox1.Text;
Response.Write("<script>alert(\"登陆成功\");</script>");
}
else
{
Response.Write("<script>alert(\"账号或密码错误\");<script>");
}
break;
default:
// Session["StuNo"] = this.TextBox1.Text;
// Response.Write(Session.ToString());
break;
}
}
}
解决方案 »
- c# richtextbox如何让在添加的字符串,总从当前屏的左上角开始显示?
- vs2008安装出错的问题,求助达人,在线等!
- SystemState类和SystemProperty类
- asp.net前台OnClientClick的使用问题。急。在线等待。。。
- 水晶报表中图标轴标签格式更改问题
- [请大家讨论]后院自动发帖代码(C#版)[ZT]
- 关于程序开机后自动运行的一个棘手问题
- 奇怪问题,web.config中不管如何配置,都只能访问login.apsx面页!
- 分不多了,49分求解Server.Transfer出错解决办法
- ComboBox TextUpdate事件 首次输入词组(广州)会触发2次,最后text= "州"
- 哪位有CSDN小助手3.0的兄弟 请发一份给我!
- 做项目时 按照正常流程需要写哪写文档,每个文档的作用是什么,以及面向哪写群体?
------------------------------------------------
string SelCmd = "SELECT COUNT(*) FROM Student WHERE Name='" + this.TextBox1.Text + "' and Pwd='" + this.TextBox2.Text + "'";
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
能够查询出结果哈