一个有关ASP.NET的问题

来源:百度知道 编辑:UC知道 时间:2024/06/08 06:42:06
我用ASP.NET写了一个关于登录的界面。编译能通过,但一调试就报错。

代码如下:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void Button1_Click(object sender, EventArgs e)
{

string conn = "Data Source=.;Initial Catalog=tm;Integrated Security=True";

SqlConnection sconn = new SqlConnection();

SqlCommand scmd = new SqlCommand();
DataSet ds = new DataSet();

string username = this.TextBox1.Text.Trim();
string userpwd = this.TextBox2.Text.Trim();

scmd.Comm

user是关键字
这样写
scmd.CommandText = "select * from [user] where id = '" + username + "' and pwd = '" + userpwd + "'";

楼主你好,你把你的数据库中表为user在换个名字.不能用这个名字的。
你改为loginuser试试看

给user 加上中括号就没事了
select * from [user] where id = '" + username + "' and pwd = '" + userpwd + "'"

user是数据库的系统关键字,高版本一般都自动帮你加上括号,建议更改名字,要不后期有时会出现麻烦