这次代码全贴上,请大家看看什么错误!!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplication5
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtname;
protected System.Web.UI.WebControls.TextBox txtpassword;
protected System.Web.UI.WebControls.TextBox txtrepassword;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.HtmlControls.HtmlGenericControl Message;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvName;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvpassword;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvrepassword;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvemail;
protected System.Web.UI.WebControls.RegularExpressionValidator revemail;
protected System.Web.UI.WebControls.TextBox txtemail;
SqlConnection myconn;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
//连接数据库
//string strconn="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=nettest;Data Source=(local);Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=SUNFX;Use Encryption for Data=False;Tag with column collation when possible=False";
string strconn = "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Initial Catalog=pubs;Data Source=Sunfx;Packet Size=4096";
myconn= new SqlConnection(strconn);
myconn.Open();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
string strsql;
strsql="select * from zhuce where username='"+txtname.Text+"'";
SqlCommand mycommand=new SqlCommand(strsql,myconn);
//用reader对象来查询用户名是否已经存在
SqlDataReader reader=mycommand.ExecuteReader();
if (reader.Read())
{
Message.InnerHtml="<p align=center><b>该用户已经存在!</b>";
reader.Close();
}
else
{
reader.Close();
strsql="INSERT INTO zhuce VALUES('"+txtname.Text+"','"+txtpassword.Text+"','"+txtemail.Text+"')";
mycommand=new SqlCommand(strsql,myconn);
mycommand.ExecuteNonQuery();
Message.InnerHtml="<p align=center><b>注册成功!</b>";
}
myconn.Close();
}
}
}
错误提示:
连接字符串 provider 中未知的连接选项。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentException: 连接字符串 provider 中未知的连接选项。
源错误:
行 41: //string strconn="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=nettest;Data Source=(local);Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=SUNFX;Use Encryption for Data=False;Tag with column collation when possible=False";
行 42: string strconn = "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Initial Catalog=pubs;Data Source=Sunfx;Packet Size=4096";
行 43: myconn= new SqlConnection(strconn);
行 44: myconn.Open();
行 45:
源文件: d:\inetpub\wwwroot\webapplication5\webform1.aspx.cs 行: 43
堆栈跟踪:
[ArgumentException: 连接字符串 provider 中未知的连接选项。]
System.Data.SqlClient.ConStringUtil.ParseStringIntoHashtable(String conString, Hashtable values)
System.Data.SqlClient.ConStringUtil.ParseConnectionString(String connectionString)
System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
System.Data.SqlClient.SqlConnection..ctor(String connectionString)
WebApplication5.WebForm1.Page_Load(Object sender, EventArgs e) in d:\inetpub\wwwroot\webapplication5\webform1.aspx.cs:43
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()