using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml;namespace RegWeb
{
public partial class landing : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected int isName()
{
int i;
String name = TextName.Text;
if (name.Trim() != "")
{
SqlConnection con = new SqlConnection("server= .;database=;uid=sa;pwd=");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from ExtUsers where UserID ='" + name + "'", con);
return i = Convert.ToInt32(cmd.ExecuteNonQuery());
con.close();
}
else
{
return 1;
}
} protected void ButtonReg_Click(object sender, EventArgs e)
{
int i = isName();
if (i <= 0)
{
if (add())
{
SqlConnection con = new SqlConnection("server=.;database=d;uid=sa;pwd=");
con.Open();
SqlCommand cmd = new SqlCommand("insert into ExtUsers(UserID,LastLogon) values('" + TextName.Text + "','" + DateTime.Now.ToString() + "')", con);
cmd.ExecuteNonQuery();
Response.Write("<script>alert('注册成功!单击确定登陆页面');location='landing.aspx';</script>");
con.Close();
}
else
{
Response.Write("<script>alert('注册失败!')<script>");
} }
else
{
Response.Write("<script>alert('会员名已经存在!')</script>");
}
}
public bool add()
{ string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(TextPass.Text, "MD5");
string sql = "insert into ExtUsers(UserID,Pass,ExtUserGroupID, UserLName ,UserFiName,Position,Notes) values('" + TextName.Text.Trim() + "','" + TextPass.Text.Trim() + "','" + TextGroupID.Text.Trim() + "','" + TextLName.Text.Trim() + "','" + TextFiName.Text.Trim() + "','" + TextPosition.Text.Trim() + "','" + TextNotes.Text.Trim() + "')";
SqlConnection con = new SqlConnection("Server=.;database=;uid=sa;pwd=");
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
int i = Convert.ToInt32(cmd.ExecuteNonQuery());
con.Close();
if (i > 0)
{
return true;
}
else
{
return false;
} }
protected void ButtonCancel_Click1(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
}} 如题,这其中那些地方有错误 protected int isName()
{
int i;
String name = TextName.Text;
if (name.Trim() != "")
{
SqlConnection con = new SqlConnection("server= .;database=;uid=sa;pwd=");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from ExtUsers where UserID ='" + name + "'", con);
return i = Convert.ToInt32(cmd.ExecuteNonQuery());
con.close();
} con.close();无法检测,如果删除有没有什么影响..
我在插入数据的时候,为什么总是提示
无法将 NULL 值插入列 'Pass',表 'admin.dbo.ExtUsers';该列不允许空值。INSERT 失败。
语句已终止。
请那位大大 帮忙解决下..在线等
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml;namespace RegWeb
{
public partial class landing : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected int isName()
{
int i;
String name = TextName.Text;
if (name.Trim() != "")
{
SqlConnection con = new SqlConnection("server= .;database=;uid=sa;pwd=");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from ExtUsers where UserID ='" + name + "'", con);
return i = Convert.ToInt32(cmd.ExecuteNonQuery());
con.close();
}
else
{
return 1;
}
} protected void ButtonReg_Click(object sender, EventArgs e)
{
int i = isName();
if (i <= 0)
{
if (add())
{
SqlConnection con = new SqlConnection("server=.;database=d;uid=sa;pwd=");
con.Open();
SqlCommand cmd = new SqlCommand("insert into ExtUsers(UserID,LastLogon) values('" + TextName.Text + "','" + DateTime.Now.ToString() + "')", con);
cmd.ExecuteNonQuery();
Response.Write("<script>alert('注册成功!单击确定登陆页面');location='landing.aspx';</script>");
con.Close();
}
else
{
Response.Write("<script>alert('注册失败!')<script>");
} }
else
{
Response.Write("<script>alert('会员名已经存在!')</script>");
}
}
public bool add()
{ string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(TextPass.Text, "MD5");
string sql = "insert into ExtUsers(UserID,Pass,ExtUserGroupID, UserLName ,UserFiName,Position,Notes) values('" + TextName.Text.Trim() + "','" + TextPass.Text.Trim() + "','" + TextGroupID.Text.Trim() + "','" + TextLName.Text.Trim() + "','" + TextFiName.Text.Trim() + "','" + TextPosition.Text.Trim() + "','" + TextNotes.Text.Trim() + "')";
SqlConnection con = new SqlConnection("Server=.;database=;uid=sa;pwd=");
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
int i = Convert.ToInt32(cmd.ExecuteNonQuery());
con.Close();
if (i > 0)
{
return true;
}
else
{
return false;
} }
protected void ButtonCancel_Click1(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
}} 如题,这其中那些地方有错误 protected int isName()
{
int i;
String name = TextName.Text;
if (name.Trim() != "")
{
SqlConnection con = new SqlConnection("server= .;database=;uid=sa;pwd=");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from ExtUsers where UserID ='" + name + "'", con);
return i = Convert.ToInt32(cmd.ExecuteNonQuery());
con.close();
} con.close();无法检测,如果删除有没有什么影响..
我在插入数据的时候,为什么总是提示
无法将 NULL 值插入列 'Pass',表 'admin.dbo.ExtUsers';该列不允许空值。INSERT 失败。
语句已终止。
请那位大大 帮忙解决下..在线等
解决方案 »
- 如何删除xml中的类似属性的东东 ??急急!!!
- winform程序发布的问题。怎么解决.net framework?
- C#问题
- Webbrowser验证码的问题
- 程序中引用Oracle.DataAccess.dll 的版本问题
- Access中插入布尔型数据
- 请教一个表问题
- picturebox和panel的MouseWheel事件怎么找不到了?
- XP下如何获得当前用户的名称?
- C#有开方函数吗?
- 用C#怎么做到 Excel和SQLServer数据的差???请高手指教!!!
- 正则表达式提取<table><tr><td>第一行</td></tr> <tr><td>第二行<td></tr> </table>中的<tr>
语句已终止。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +109
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +57
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +207
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2433
System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) +192
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +256
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +117
RegWeb.landing.ButtonReg_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\Login\Reg.cs:50
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +78
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +100
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2863
这是错误的地方,刚1楼说的我改了 没有用 谢谢了
{
int i;
String name = TextName.Text;
if (name.Trim() != "")
{
SqlConnection con = new SqlConnection("server=hwang;database=dataclub;uid=sa;pwd=");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from ExtUsers where UserID ='" + name + "'", con);
return i = Convert.ToInt32(cmd.ExecuteNonQuery());
con.Close();
}
else
{
return 1;
}
} protected void ButtonReg_Click(object sender, EventArgs e)
{
int i = isName();
String name = TextName.Text;
if (i <= 0)
{
if (add())
{
SqlConnection con = new SqlConnection("server=hwang;database=dataclub;uid=sa;pwd=");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from ExtUsers where UserID ='" + name + "'", con);
cmd.ExecuteNonQuery();
Response.Write("<script>alert('注册成功!单击确定登陆页面');location='main.aspx';</script>");
con.Close();
}
else
{
Response.Write("<script>alert('注册失败!')<script>");
} }
else
{
Response.Write("<script>alert('会员名已经存在!')</script>");
}
}
public bool add()
{ string pass = FormsAuthentication.HashPasswordForStoringInConfigFile(TextPass.Text, "MD5");
string sql = "insert into ExtUsers(UserID,Pass,ExtUserGroupID, UserLName ,UserFiName,Position,Notes,LastLogon) values('" + TextName.Text.Trim() + "','" + pass + "','" + TextGroupID.Text.Trim() + "','" + TextLName.Text.Trim() + "','" + TextFiName.Text.Trim() + "','" + TextPosition.Text.Trim() + "','" + TextNotes.Text.Trim() + "','" + DateTime.Now.ToString() + "')";
SqlConnection con = new SqlConnection("Server=hwang;database=dataclub;uid=sa;pwd=");
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
int i = Convert.ToInt32(cmd.ExecuteNonQuery());
con.Close();
if (i > 0)
{
return true;
}
else
{
return false;
} }
protected void ButtonCancel_Click1(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
}}
所以你在插入的记录的时候 这个字段是必须有值的! 如果没值就是你刚才看到的错误....
if (add())
{
// SqlConnection con = new SqlConnection("server=hwang;database=dataclub;uid=sa;pwd=");
// con.Open();
// SqlCommand cmd = new SqlCommand("select count(*) from ExtUsers where UserID ='" + name + "'", con);
// cmd.ExecuteNonQuery();
//为什么要写上面的几句? 用意何在?
Response.Write("<script>alert('注册成功!单击确定登陆页面');location='main.aspx';</script>");
con.Close();
}
else
{
Response.Write("<script>alert('注册失败!')<script>");
}