--------------------------------------------------------------------------------
用户 'PC-201101051415\ASPNET' 登录失败。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 用户 'PC-201101051415\ASPNET' 登录失败。
源错误:
行 50: string sql = "select names from members where names=\'" + text + "\'";
行 51:
行 52: myconn.Open();
行 53: SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
行 54: DataTable mydt = new DataTable();
源文件: i:\flydo\regedit\App_Code\checkcounts.cs 行: 52
堆栈跟踪:
[SqlException (0x80131904): 用户 'PC-201101051415\ASPNET' 登录失败。]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +821651
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1932
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +33
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +172
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +381
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +181
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +173
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +357
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +30
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +494
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
System.Data.SqlClient.SqlConnection.Open() +111
checkcounts.Thesames(String text) in i:\flydo\regedit\App_Code\checkcounts.cs:52
_Default.Button1_Click(Object sender, EventArgs e) in i:\flydo\regedit\register.aspx.cs:103
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5087
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.1882; ASP.NET 版本:2.0.50727.1879
web.config里面的连接字符串
<connectionStrings>
<add name="connstring" connectionString="Data Source=PC-201101051415;Initial Catalog=membersys;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
21 个解决方案
#1
都说了异常详细信息: System.Data.SqlClient.SqlException: 用户 'PC-201101051415\ASPNET' 登录失败。
密码对么。。
密码对么。。
#2
首先请确保数据库服务器的实例,账号,密码是否正确
其次检查一下DB服务器是否开启
其次检查一下DB服务器是否开启
#3
用你sql服务管理器看看。。
把其它不是这个名字的实例给停了
#4
使用sql企业管理器连接看是否能够连接
#5
确保数据库服务器的实例,账号,密码是否正确
你看你能ping通数据库服务器不
你看你能ping通数据库服务器不
#6
用的是WIndows模式连接的。 本来是可以连接上的,但是因为可以重复注册相同的信息,我就像加一个判断,如果在数据库里能检索到已有信息,则提示不能注册。结果就开始数据库登陆失败,即使我改回来,也是登录数据库失败
#7
可以连上 WINDOWS模式和SQL模式都能连接上
#8
数据库在本地。。我直接打开SQL Server management studio 2种模式都能连接上
#9
断点一下。在你加的方法那。看连接字符串是什么。。
#10
DB? ODBC么? 我直接连接的数据库SQL 2005的
我不大明白你说的意思 能详细点么?
#11
web.config里面的连接字符串
<connectionStrings>
<add name="connstring" connectionString="Data Source=PC-201101051415;Initial Catalog=membersys;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
Data Source=PC-201101051415;Initial Catalog=membersys;Integrated Security=True
这一段
#12
我把我的全部代码粘上来吧,肯定是有细节我不知道的,希望各位达人不吝赐教哇!
register.aspx页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="register.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%;">
<tr>
<td colspan="2">
用户注册</td>
</tr>
<tr>
<td width="100px">
用户名*</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="检测是否可用" onclick="Button1_Click" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="用户名不能为空"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
真实姓名*</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2" ErrorMessage="姓名不能为空"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
密码*</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox3" ErrorMessage="密码不能为空"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
确认密码*</td>
<td>
<asp:TextBox ID="TextBox4" runat="server" TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox3" ControlToValidate="TextBox4" ErrorMessage="密码不一致"></asp:CompareValidator>
</td>
</tr>
<tr>
<td>
性别*</td>
<td>
<asp:RadioButtonList ID="sexList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Selected="True">男</asp:ListItem>
<asp:ListItem>女</asp:ListItem>
<asp:ListItem>中性</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
上传头像</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
</div>
<asp:Button ID="Button2" runat="server" Text="提交" onclick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="重置" onclick="Button3_Click" />
<br />
<asp:Image ID="Image1" runat="server" Height="99px" Width="99px" />
</form>
</body>
</html>
register.aspx页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="register.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%;">
<tr>
<td colspan="2">
用户注册</td>
</tr>
<tr>
<td width="100px">
用户名*</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="检测是否可用" onclick="Button1_Click" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="用户名不能为空"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
真实姓名*</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2" ErrorMessage="姓名不能为空"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
密码*</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox3" ErrorMessage="密码不能为空"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
确认密码*</td>
<td>
<asp:TextBox ID="TextBox4" runat="server" TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox3" ControlToValidate="TextBox4" ErrorMessage="密码不一致"></asp:CompareValidator>
</td>
</tr>
<tr>
<td>
性别*</td>
<td>
<asp:RadioButtonList ID="sexList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Selected="True">男</asp:ListItem>
<asp:ListItem>女</asp:ListItem>
<asp:ListItem>中性</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
上传头像</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
</div>
<asp:Button ID="Button2" runat="server" Text="提交" onclick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="重置" onclick="Button3_Click" />
<br />
<asp:Image ID="Image1" runat="server" Height="99px" Width="99px" />
</form>
</body>
</html>
#13
试试在其他电脑上能不能通过sql身份登陆上?
是不是text 包含了特殊字符?
string sql = "select names from members where names=\'" + text + "\'";
是不是text 包含了特殊字符?
string sql = "select names from members where names=\'" + text + "\'";
#14
System.Data.SqlClient.SqlException: 用户 'PC-201101051415\ASPNET' 登录失败
这是不是密码错了。。
这是不是密码错了。。
#15
路过! 看看加上的判断语句有错不?
#16
register.aspx.cs页面
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
string name = FileUpload1.FileName;
string size = FileUpload1.PostedFile.ContentLength.ToString();
string type = FileUpload1.PostedFile.ContentType;
string type1 = name.Substring(name.LastIndexOf(".") + 1);
string ipath = Server.MapPath("userphotos\\") + name;
string sqlpath = "userphotos\\" + name;
if (type1 == "jpg" || type1 == "bmp" || type1 == "gif" || type1 == "png")
{
FileUpload1.SaveAs(ipath);
//GetConn abc = new GetConn();
//SqlConnection myconn = abc.GetCon();
//string sql = "select names from members";
//myconn.Open();
//SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
//DataTable mydt = new DataTable();
//myap.Fill(mydt);
//myconn.Close();
//for (int i = 0; i < mydt.Rows.Count; i++)
//{
// if (mydt.Rows[i][0].ToString() == TextBox1.Text)
// {
// Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户已被注册');</script>", false);
// }
//}
InserRecord IR = new InserRecord();
IR.InsertSql("members", new string[] { "names", "realname", "password", "sex", "userphoto" }, new string[] { TextBox1.Text, TextBox2.Text, TextBox3.Text, sexList1.SelectedItem.Text.ToString(), sqlpath });
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('新用户注册成功');</script>", false);
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户已被注册');</script>", false);
//string ccc = IR.chek("members", new string[] { "names", "realname", "password", "sex", "userphoto" }, new string[] { TextBox1.Text, TextBox2.Text, TextBox3.Text, sexList1.SelectedItem.Text.ToString(), sqlpath });
Image1.ImageUrl = sqlpath;
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('图片格式不正确');</script>", false);
}
{ "names", "realname", "password", "sex", "userphoto" }, new string[] { TextBox1.Text, TextBox2.Text, TextBox3.Text, sexList1.SelectedItem.Text.ToString(), sqlpath });
}
protected void Button3_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
protected void Button1_Click(object sender, EventArgs e)
{
checkcounts acc=new checkcounts();
if(acc.Thesames(TextBox1.Text))
{
Button1.Text = "恭喜你,可以注册此账号";
}
else
{
Button1.Text = "很遗憾,该用户名已被占用";
}
}
}
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
string name = FileUpload1.FileName;
string size = FileUpload1.PostedFile.ContentLength.ToString();
string type = FileUpload1.PostedFile.ContentType;
string type1 = name.Substring(name.LastIndexOf(".") + 1);
string ipath = Server.MapPath("userphotos\\") + name;
string sqlpath = "userphotos\\" + name;
if (type1 == "jpg" || type1 == "bmp" || type1 == "gif" || type1 == "png")
{
FileUpload1.SaveAs(ipath);
//GetConn abc = new GetConn();
//SqlConnection myconn = abc.GetCon();
//string sql = "select names from members";
//myconn.Open();
//SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
//DataTable mydt = new DataTable();
//myap.Fill(mydt);
//myconn.Close();
//for (int i = 0; i < mydt.Rows.Count; i++)
//{
// if (mydt.Rows[i][0].ToString() == TextBox1.Text)
// {
// Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户已被注册');</script>", false);
// }
//}
InserRecord IR = new InserRecord();
IR.InsertSql("members", new string[] { "names", "realname", "password", "sex", "userphoto" }, new string[] { TextBox1.Text, TextBox2.Text, TextBox3.Text, sexList1.SelectedItem.Text.ToString(), sqlpath });
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('新用户注册成功');</script>", false);
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户已被注册');</script>", false);
//string ccc = IR.chek("members", new string[] { "names", "realname", "password", "sex", "userphoto" }, new string[] { TextBox1.Text, TextBox2.Text, TextBox3.Text, sexList1.SelectedItem.Text.ToString(), sqlpath });
Image1.ImageUrl = sqlpath;
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('图片格式不正确');</script>", false);
}
{ "names", "realname", "password", "sex", "userphoto" }, new string[] { TextBox1.Text, TextBox2.Text, TextBox3.Text, sexList1.SelectedItem.Text.ToString(), sqlpath });
}
protected void Button3_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
protected void Button1_Click(object sender, EventArgs e)
{
checkcounts acc=new checkcounts();
if(acc.Thesames(TextBox1.Text))
{
Button1.Text = "恭喜你,可以注册此账号";
}
else
{
Button1.Text = "很遗憾,该用户名已被占用";
}
}
}
#17
InserRecord.cs 代码段
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
///InserRecord 的摘要说明
/// </summary>
public class InserRecord
{
public InserRecord()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public void InsertSql(string tablename, string[] parameters, string[] values)
{
string _Parameter = "";
for (int i = 0; i < parameters.Length; i++)
{
_Parameter += parameters[i]+"," ;
}
if (_Parameter != "")
{
_Parameter = _Parameter.Remove(_Parameter.LastIndexOf(','),1);
}
string _values = "";
for(int j=0;j<values.Length;j++)
{
_values += "'" + values[j] + "',";
}
if (_values != "")
{
_values = _values.Remove(_values.LastIndexOf(','),1);
}
try
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
myconn.Open();
string sql = "insert into " + tablename + "(" + _Parameter + ")values(" + _values + ")";
SqlCommand dbc = new SqlCommand(sql, myconn);
dbc.ExecuteNonQuery();
myconn.Close();
}
catch(Exception ex)
{
string s = ex.Message.ToString();
}
}
public string chek(string tablename, string[] parameters, string[] values)
{
string _Parameter = "";
for (int i = 0; i < parameters.Length; i++)
{
_Parameter += parameters[i] + ",";
}
if (_Parameter != "")
{
_Parameter = _Parameter.Remove(_Parameter.LastIndexOf(','), 1);
}
string _values = "";
for (int j = 0; j < values.Length; j++)
{
_values += "'" + values[j] + "',";
}
if (_values != "")
{
_values = _values.Remove(_values.LastIndexOf(','), 1);
}
try
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
myconn.Open();
string sql = "insert into " + tablename + " (" + _Parameter + ")values(" + _values + ")";
SqlCommand dbc = new SqlCommand(sql, myconn);
dbc.ExecuteNonQuery();
myconn.Close();
return "ok";
}
catch (Exception ex)
{
string s = ex.Message.ToString();
string sql = "inseter into" + tablename + "(" + _Parameter + ")values(" + _values + ")";
return s+"<br>"+sql;
}
}
}
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
///InserRecord 的摘要说明
/// </summary>
public class InserRecord
{
public InserRecord()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public void InsertSql(string tablename, string[] parameters, string[] values)
{
string _Parameter = "";
for (int i = 0; i < parameters.Length; i++)
{
_Parameter += parameters[i]+"," ;
}
if (_Parameter != "")
{
_Parameter = _Parameter.Remove(_Parameter.LastIndexOf(','),1);
}
string _values = "";
for(int j=0;j<values.Length;j++)
{
_values += "'" + values[j] + "',";
}
if (_values != "")
{
_values = _values.Remove(_values.LastIndexOf(','),1);
}
try
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
myconn.Open();
string sql = "insert into " + tablename + "(" + _Parameter + ")values(" + _values + ")";
SqlCommand dbc = new SqlCommand(sql, myconn);
dbc.ExecuteNonQuery();
myconn.Close();
}
catch(Exception ex)
{
string s = ex.Message.ToString();
}
}
public string chek(string tablename, string[] parameters, string[] values)
{
string _Parameter = "";
for (int i = 0; i < parameters.Length; i++)
{
_Parameter += parameters[i] + ",";
}
if (_Parameter != "")
{
_Parameter = _Parameter.Remove(_Parameter.LastIndexOf(','), 1);
}
string _values = "";
for (int j = 0; j < values.Length; j++)
{
_values += "'" + values[j] + "',";
}
if (_values != "")
{
_values = _values.Remove(_values.LastIndexOf(','), 1);
}
try
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
myconn.Open();
string sql = "insert into " + tablename + " (" + _Parameter + ")values(" + _values + ")";
SqlCommand dbc = new SqlCommand(sql, myconn);
dbc.ExecuteNonQuery();
myconn.Close();
return "ok";
}
catch (Exception ex)
{
string s = ex.Message.ToString();
string sql = "inseter into" + tablename + "(" + _Parameter + ")values(" + _values + ")";
return s+"<br>"+sql;
}
}
}
#18
你用你的账号密码 在sql工具登录下 看能不能登录。。
#19
判断代码段
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
///checkcounts 的摘要说明
/// </summary>
public class checkcounts
{
public checkcounts()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public string Thesame(string text)
{
try
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
string sql = "select names from members where names=\'" + text + "\'";
myconn.Open();
SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
DataTable mydt = new DataTable();
myap.Fill(mydt);
myconn.Close();
return "OK";
}
catch (Exception eee)
{
return eee.ToString();
}
}
public bool Thesames(string text)
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
string sql = "select names from members where names=\'" + text + "\'";
myconn.Open();
SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
DataTable mydt = new DataTable();
myap.Fill(mydt);
myconn.Close();
//for (int i = 0; i < mydt.Rows.Count; i++)
//{
// if (mydt.Rows[i][0].ToString() == text)
// {
// //Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户已被注册');</script>", false);
// return false;
// break
// }
// else
// {
// return true;
// }
//}
if (mydt.Rows.Count < 0)
{
return true;
}
else
{
return false;
}
}
}
数据库连接代码段
using System;
using System.Data;
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;
using System.Data.SqlClient;
/// <summary>
/// GetConnetion 的摘要说明
/// </summary>
public class GetConnetion
{
string connString;
public GetConnetion()
{
//
// TODO: 在此处添加构造函数逻辑
//
connString = ConfigurationManager.ConnectionStrings["ConnectString"].ToString();//连接数据库字符串
}
public SqlConnection Getconn()
{
connString = ConfigurationManager.ConnectionStrings["ConnectString"].ToString();
SqlConnection conn = new SqlConnection(connString);
return conn;
}
}
#20
我刚才发现 注册已然能用 但是检测用户账号那个BUTTON1 是有问题的~
#21
为什么一样的打开连接数据库 注册就可以是正常的
检测账户那里就不对?! 我没找到2者的区别啊。。。 求指点
判断的代码
public string Thesame(string text)
{
try
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
string sql = "select names from members where names=\'" + text + "\'";
myconn.Open();
SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
DataTable mydt = new DataTable();
myap.Fill(mydt);
myconn.Close();
return "OK";
}
catch (Exception eee)
{
return eee.ToString();
}
}
public bool Thesames(string text)
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
string sql = "select names from members where names=\'" + text + "\'";
myconn.Open();
SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
DataTable mydt = new DataTable();
myap.Fill(mydt);
myconn.Close();
//for (int i = 0; i < mydt.Rows.Count; i++)
//{
// if (mydt.Rows[i][0].ToString() == text)
// {
// //Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户已被注册');</script>", false);
// return false;
// break
// }
// else
// {
// return true;
// }
//}
if (mydt.Rows.Count < 0)
{
return true;
}
else
{
return false;
}
}
}
检测账户那里就不对?! 我没找到2者的区别啊。。。 求指点
判断的代码
public string Thesame(string text)
{
try
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
string sql = "select names from members where names=\'" + text + "\'";
myconn.Open();
SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
DataTable mydt = new DataTable();
myap.Fill(mydt);
myconn.Close();
return "OK";
}
catch (Exception eee)
{
return eee.ToString();
}
}
public bool Thesames(string text)
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
string sql = "select names from members where names=\'" + text + "\'";
myconn.Open();
SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
DataTable mydt = new DataTable();
myap.Fill(mydt);
myconn.Close();
//for (int i = 0; i < mydt.Rows.Count; i++)
//{
// if (mydt.Rows[i][0].ToString() == text)
// {
// //Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户已被注册');</script>", false);
// return false;
// break
// }
// else
// {
// return true;
// }
//}
if (mydt.Rows.Count < 0)
{
return true;
}
else
{
return false;
}
}
}
#1
都说了异常详细信息: System.Data.SqlClient.SqlException: 用户 'PC-201101051415\ASPNET' 登录失败。
密码对么。。
密码对么。。
#2
首先请确保数据库服务器的实例,账号,密码是否正确
其次检查一下DB服务器是否开启
其次检查一下DB服务器是否开启
#3
用你sql服务管理器看看。。
把其它不是这个名字的实例给停了
#4
使用sql企业管理器连接看是否能够连接
#5
确保数据库服务器的实例,账号,密码是否正确
你看你能ping通数据库服务器不
你看你能ping通数据库服务器不
#6
用的是WIndows模式连接的。 本来是可以连接上的,但是因为可以重复注册相同的信息,我就像加一个判断,如果在数据库里能检索到已有信息,则提示不能注册。结果就开始数据库登陆失败,即使我改回来,也是登录数据库失败
#7
可以连上 WINDOWS模式和SQL模式都能连接上
#8
数据库在本地。。我直接打开SQL Server management studio 2种模式都能连接上
#9
断点一下。在你加的方法那。看连接字符串是什么。。
#10
DB? ODBC么? 我直接连接的数据库SQL 2005的
我不大明白你说的意思 能详细点么?
#11
web.config里面的连接字符串
<connectionStrings>
<add name="connstring" connectionString="Data Source=PC-201101051415;Initial Catalog=membersys;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
Data Source=PC-201101051415;Initial Catalog=membersys;Integrated Security=True
这一段
#12
我把我的全部代码粘上来吧,肯定是有细节我不知道的,希望各位达人不吝赐教哇!
register.aspx页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="register.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%;">
<tr>
<td colspan="2">
用户注册</td>
</tr>
<tr>
<td width="100px">
用户名*</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="检测是否可用" onclick="Button1_Click" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="用户名不能为空"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
真实姓名*</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2" ErrorMessage="姓名不能为空"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
密码*</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox3" ErrorMessage="密码不能为空"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
确认密码*</td>
<td>
<asp:TextBox ID="TextBox4" runat="server" TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox3" ControlToValidate="TextBox4" ErrorMessage="密码不一致"></asp:CompareValidator>
</td>
</tr>
<tr>
<td>
性别*</td>
<td>
<asp:RadioButtonList ID="sexList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Selected="True">男</asp:ListItem>
<asp:ListItem>女</asp:ListItem>
<asp:ListItem>中性</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
上传头像</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
</div>
<asp:Button ID="Button2" runat="server" Text="提交" onclick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="重置" onclick="Button3_Click" />
<br />
<asp:Image ID="Image1" runat="server" Height="99px" Width="99px" />
</form>
</body>
</html>
register.aspx页面代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="register.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%;">
<tr>
<td colspan="2">
用户注册</td>
</tr>
<tr>
<td width="100px">
用户名*</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="检测是否可用" onclick="Button1_Click" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="用户名不能为空"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
真实姓名*</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2" ErrorMessage="姓名不能为空"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
密码*</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox3" ErrorMessage="密码不能为空"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
确认密码*</td>
<td>
<asp:TextBox ID="TextBox4" runat="server" TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox3" ControlToValidate="TextBox4" ErrorMessage="密码不一致"></asp:CompareValidator>
</td>
</tr>
<tr>
<td>
性别*</td>
<td>
<asp:RadioButtonList ID="sexList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Selected="True">男</asp:ListItem>
<asp:ListItem>女</asp:ListItem>
<asp:ListItem>中性</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
上传头像</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
</div>
<asp:Button ID="Button2" runat="server" Text="提交" onclick="Button2_Click" />
<asp:Button ID="Button3" runat="server" Text="重置" onclick="Button3_Click" />
<br />
<asp:Image ID="Image1" runat="server" Height="99px" Width="99px" />
</form>
</body>
</html>
#13
试试在其他电脑上能不能通过sql身份登陆上?
是不是text 包含了特殊字符?
string sql = "select names from members where names=\'" + text + "\'";
是不是text 包含了特殊字符?
string sql = "select names from members where names=\'" + text + "\'";
#14
System.Data.SqlClient.SqlException: 用户 'PC-201101051415\ASPNET' 登录失败
这是不是密码错了。。
这是不是密码错了。。
#15
路过! 看看加上的判断语句有错不?
#16
register.aspx.cs页面
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
string name = FileUpload1.FileName;
string size = FileUpload1.PostedFile.ContentLength.ToString();
string type = FileUpload1.PostedFile.ContentType;
string type1 = name.Substring(name.LastIndexOf(".") + 1);
string ipath = Server.MapPath("userphotos\\") + name;
string sqlpath = "userphotos\\" + name;
if (type1 == "jpg" || type1 == "bmp" || type1 == "gif" || type1 == "png")
{
FileUpload1.SaveAs(ipath);
//GetConn abc = new GetConn();
//SqlConnection myconn = abc.GetCon();
//string sql = "select names from members";
//myconn.Open();
//SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
//DataTable mydt = new DataTable();
//myap.Fill(mydt);
//myconn.Close();
//for (int i = 0; i < mydt.Rows.Count; i++)
//{
// if (mydt.Rows[i][0].ToString() == TextBox1.Text)
// {
// Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户已被注册');</script>", false);
// }
//}
InserRecord IR = new InserRecord();
IR.InsertSql("members", new string[] { "names", "realname", "password", "sex", "userphoto" }, new string[] { TextBox1.Text, TextBox2.Text, TextBox3.Text, sexList1.SelectedItem.Text.ToString(), sqlpath });
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('新用户注册成功');</script>", false);
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户已被注册');</script>", false);
//string ccc = IR.chek("members", new string[] { "names", "realname", "password", "sex", "userphoto" }, new string[] { TextBox1.Text, TextBox2.Text, TextBox3.Text, sexList1.SelectedItem.Text.ToString(), sqlpath });
Image1.ImageUrl = sqlpath;
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('图片格式不正确');</script>", false);
}
{ "names", "realname", "password", "sex", "userphoto" }, new string[] { TextBox1.Text, TextBox2.Text, TextBox3.Text, sexList1.SelectedItem.Text.ToString(), sqlpath });
}
protected void Button3_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
protected void Button1_Click(object sender, EventArgs e)
{
checkcounts acc=new checkcounts();
if(acc.Thesames(TextBox1.Text))
{
Button1.Text = "恭喜你,可以注册此账号";
}
else
{
Button1.Text = "很遗憾,该用户名已被占用";
}
}
}
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
string name = FileUpload1.FileName;
string size = FileUpload1.PostedFile.ContentLength.ToString();
string type = FileUpload1.PostedFile.ContentType;
string type1 = name.Substring(name.LastIndexOf(".") + 1);
string ipath = Server.MapPath("userphotos\\") + name;
string sqlpath = "userphotos\\" + name;
if (type1 == "jpg" || type1 == "bmp" || type1 == "gif" || type1 == "png")
{
FileUpload1.SaveAs(ipath);
//GetConn abc = new GetConn();
//SqlConnection myconn = abc.GetCon();
//string sql = "select names from members";
//myconn.Open();
//SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
//DataTable mydt = new DataTable();
//myap.Fill(mydt);
//myconn.Close();
//for (int i = 0; i < mydt.Rows.Count; i++)
//{
// if (mydt.Rows[i][0].ToString() == TextBox1.Text)
// {
// Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户已被注册');</script>", false);
// }
//}
InserRecord IR = new InserRecord();
IR.InsertSql("members", new string[] { "names", "realname", "password", "sex", "userphoto" }, new string[] { TextBox1.Text, TextBox2.Text, TextBox3.Text, sexList1.SelectedItem.Text.ToString(), sqlpath });
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('新用户注册成功');</script>", false);
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户已被注册');</script>", false);
//string ccc = IR.chek("members", new string[] { "names", "realname", "password", "sex", "userphoto" }, new string[] { TextBox1.Text, TextBox2.Text, TextBox3.Text, sexList1.SelectedItem.Text.ToString(), sqlpath });
Image1.ImageUrl = sqlpath;
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('图片格式不正确');</script>", false);
}
{ "names", "realname", "password", "sex", "userphoto" }, new string[] { TextBox1.Text, TextBox2.Text, TextBox3.Text, sexList1.SelectedItem.Text.ToString(), sqlpath });
}
protected void Button3_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
protected void Button1_Click(object sender, EventArgs e)
{
checkcounts acc=new checkcounts();
if(acc.Thesames(TextBox1.Text))
{
Button1.Text = "恭喜你,可以注册此账号";
}
else
{
Button1.Text = "很遗憾,该用户名已被占用";
}
}
}
#17
InserRecord.cs 代码段
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
///InserRecord 的摘要说明
/// </summary>
public class InserRecord
{
public InserRecord()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public void InsertSql(string tablename, string[] parameters, string[] values)
{
string _Parameter = "";
for (int i = 0; i < parameters.Length; i++)
{
_Parameter += parameters[i]+"," ;
}
if (_Parameter != "")
{
_Parameter = _Parameter.Remove(_Parameter.LastIndexOf(','),1);
}
string _values = "";
for(int j=0;j<values.Length;j++)
{
_values += "'" + values[j] + "',";
}
if (_values != "")
{
_values = _values.Remove(_values.LastIndexOf(','),1);
}
try
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
myconn.Open();
string sql = "insert into " + tablename + "(" + _Parameter + ")values(" + _values + ")";
SqlCommand dbc = new SqlCommand(sql, myconn);
dbc.ExecuteNonQuery();
myconn.Close();
}
catch(Exception ex)
{
string s = ex.Message.ToString();
}
}
public string chek(string tablename, string[] parameters, string[] values)
{
string _Parameter = "";
for (int i = 0; i < parameters.Length; i++)
{
_Parameter += parameters[i] + ",";
}
if (_Parameter != "")
{
_Parameter = _Parameter.Remove(_Parameter.LastIndexOf(','), 1);
}
string _values = "";
for (int j = 0; j < values.Length; j++)
{
_values += "'" + values[j] + "',";
}
if (_values != "")
{
_values = _values.Remove(_values.LastIndexOf(','), 1);
}
try
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
myconn.Open();
string sql = "insert into " + tablename + " (" + _Parameter + ")values(" + _values + ")";
SqlCommand dbc = new SqlCommand(sql, myconn);
dbc.ExecuteNonQuery();
myconn.Close();
return "ok";
}
catch (Exception ex)
{
string s = ex.Message.ToString();
string sql = "inseter into" + tablename + "(" + _Parameter + ")values(" + _values + ")";
return s+"<br>"+sql;
}
}
}
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
///InserRecord 的摘要说明
/// </summary>
public class InserRecord
{
public InserRecord()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public void InsertSql(string tablename, string[] parameters, string[] values)
{
string _Parameter = "";
for (int i = 0; i < parameters.Length; i++)
{
_Parameter += parameters[i]+"," ;
}
if (_Parameter != "")
{
_Parameter = _Parameter.Remove(_Parameter.LastIndexOf(','),1);
}
string _values = "";
for(int j=0;j<values.Length;j++)
{
_values += "'" + values[j] + "',";
}
if (_values != "")
{
_values = _values.Remove(_values.LastIndexOf(','),1);
}
try
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
myconn.Open();
string sql = "insert into " + tablename + "(" + _Parameter + ")values(" + _values + ")";
SqlCommand dbc = new SqlCommand(sql, myconn);
dbc.ExecuteNonQuery();
myconn.Close();
}
catch(Exception ex)
{
string s = ex.Message.ToString();
}
}
public string chek(string tablename, string[] parameters, string[] values)
{
string _Parameter = "";
for (int i = 0; i < parameters.Length; i++)
{
_Parameter += parameters[i] + ",";
}
if (_Parameter != "")
{
_Parameter = _Parameter.Remove(_Parameter.LastIndexOf(','), 1);
}
string _values = "";
for (int j = 0; j < values.Length; j++)
{
_values += "'" + values[j] + "',";
}
if (_values != "")
{
_values = _values.Remove(_values.LastIndexOf(','), 1);
}
try
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
myconn.Open();
string sql = "insert into " + tablename + " (" + _Parameter + ")values(" + _values + ")";
SqlCommand dbc = new SqlCommand(sql, myconn);
dbc.ExecuteNonQuery();
myconn.Close();
return "ok";
}
catch (Exception ex)
{
string s = ex.Message.ToString();
string sql = "inseter into" + tablename + "(" + _Parameter + ")values(" + _values + ")";
return s+"<br>"+sql;
}
}
}
#18
你用你的账号密码 在sql工具登录下 看能不能登录。。
#19
判断代码段
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
///checkcounts 的摘要说明
/// </summary>
public class checkcounts
{
public checkcounts()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public string Thesame(string text)
{
try
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
string sql = "select names from members where names=\'" + text + "\'";
myconn.Open();
SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
DataTable mydt = new DataTable();
myap.Fill(mydt);
myconn.Close();
return "OK";
}
catch (Exception eee)
{
return eee.ToString();
}
}
public bool Thesames(string text)
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
string sql = "select names from members where names=\'" + text + "\'";
myconn.Open();
SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
DataTable mydt = new DataTable();
myap.Fill(mydt);
myconn.Close();
//for (int i = 0; i < mydt.Rows.Count; i++)
//{
// if (mydt.Rows[i][0].ToString() == text)
// {
// //Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户已被注册');</script>", false);
// return false;
// break
// }
// else
// {
// return true;
// }
//}
if (mydt.Rows.Count < 0)
{
return true;
}
else
{
return false;
}
}
}
数据库连接代码段
using System;
using System.Data;
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;
using System.Data.SqlClient;
/// <summary>
/// GetConnetion 的摘要说明
/// </summary>
public class GetConnetion
{
string connString;
public GetConnetion()
{
//
// TODO: 在此处添加构造函数逻辑
//
connString = ConfigurationManager.ConnectionStrings["ConnectString"].ToString();//连接数据库字符串
}
public SqlConnection Getconn()
{
connString = ConfigurationManager.ConnectionStrings["ConnectString"].ToString();
SqlConnection conn = new SqlConnection(connString);
return conn;
}
}
#20
我刚才发现 注册已然能用 但是检测用户账号那个BUTTON1 是有问题的~
#21
为什么一样的打开连接数据库 注册就可以是正常的
检测账户那里就不对?! 我没找到2者的区别啊。。。 求指点
判断的代码
public string Thesame(string text)
{
try
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
string sql = "select names from members where names=\'" + text + "\'";
myconn.Open();
SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
DataTable mydt = new DataTable();
myap.Fill(mydt);
myconn.Close();
return "OK";
}
catch (Exception eee)
{
return eee.ToString();
}
}
public bool Thesames(string text)
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
string sql = "select names from members where names=\'" + text + "\'";
myconn.Open();
SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
DataTable mydt = new DataTable();
myap.Fill(mydt);
myconn.Close();
//for (int i = 0; i < mydt.Rows.Count; i++)
//{
// if (mydt.Rows[i][0].ToString() == text)
// {
// //Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户已被注册');</script>", false);
// return false;
// break
// }
// else
// {
// return true;
// }
//}
if (mydt.Rows.Count < 0)
{
return true;
}
else
{
return false;
}
}
}
检测账户那里就不对?! 我没找到2者的区别啊。。。 求指点
判断的代码
public string Thesame(string text)
{
try
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
string sql = "select names from members where names=\'" + text + "\'";
myconn.Open();
SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
DataTable mydt = new DataTable();
myap.Fill(mydt);
myconn.Close();
return "OK";
}
catch (Exception eee)
{
return eee.ToString();
}
}
public bool Thesames(string text)
{
GetConn abc = new GetConn();
SqlConnection myconn = abc.GetCon();
string sql = "select names from members where names=\'" + text + "\'";
myconn.Open();
SqlDataAdapter myap = new SqlDataAdapter(sql, myconn);
DataTable mydt = new DataTable();
myap.Fill(mydt);
myconn.Close();
//for (int i = 0; i < mydt.Rows.Count; i++)
//{
// if (mydt.Rows[i][0].ToString() == text)
// {
// //Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此用户已被注册');</script>", false);
// return false;
// break
// }
// else
// {
// return true;
// }
//}
if (mydt.Rows.Count < 0)
{
return true;
}
else
{
return false;
}
}
}