using System;
using System.Collections;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace FriendsReunion.secure
{
/// <summary>
/// NewUser 的摘要说明。
/// </summary>
public class NewUser : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button BtnAccept;
protected System.Web.UI.WebControls.TextBox txtFName;
protected System.Web.UI.WebControls.TextBox txtLName;
protected System.Web.UI.WebControls.TextBox txtAddr;
protected System.Web.UI.WebControls.TextBox txtPhone;
protected System.Web.UI.WebControls.TextBox txtBirth;
protected System.Web.UI.WebControls.TextBox txtLogin;
protected System.Web.UI.WebControls.TextBox txtPWD;
protected System.Web.UI.WebControls.RequiredFieldValidator reqLogin;
protected System.Web.UI.WebControls.RequiredFieldValidator reqPWD;
protected System.Web.UI.WebControls.RequiredFieldValidator reqFname;
protected System.Web.UI.WebControls.RequiredFieldValidator reqLname;
protected System.Web.UI.WebControls.RequiredFieldValidator reqAddr;
protected System.Web.UI.WebControls.TextBox txtMobile;
protected System.Web.UI.WebControls.RequiredFieldValidator reqPhone;
protected System.Web.UI.WebControls.RequiredFieldValidator reqMobile;
protected System.Web.UI.WebControls.RequiredFieldValidator reqEmail;
protected System.Web.UI.WebControls.RequiredFieldValidator reqBirth;
protected System.Web.UI.WebControls.CompareValidator CompBirth;
protected System.Web.UI.WebControls.RegularExpressionValidator regPhone;
protected System.Web.UI.WebControls.RegularExpressionValidator regEmail;
protected System.Web.UI.WebControls.Label LblMessage;
protected System.Web.UI.WebControls.ValidationSummary ValErrors;
protected System.Web.UI.WebControls.TextBox txtEmail;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#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.BtnAccept.Click += new System.EventHandler(this.BtnAccept_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void BtnAccept_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
string sql;
OleDbCommand OleDBCom;
StringBuilder strBul=new StringBuilder();
ArrayList values=new ArrayList();
sql=@"insert into [User](UserID,Login,PassWord,FirstName,LastName,
DateOfBirth,Email,IsAdministrator,Address,
MobileNumber,DateOfBirth)Values(
'{0}','{1}','{2}','{3}','{4}','{5}','{6}',
'{7}',{8},{9},{10})";
/* strBul.Append("insert into [User]");
strBul.Append("(UserID,Login,PassWord,FirstName,LastName");
strBul.Append("DateOfBirth,Email,IsAdministrator,Address");
strBul.Append("MobileNumber,DateOfBirth)");
strBul.Append("Values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}',");
strBul.Append("{7},{8},{9})");*/
values.Add(Guid.NewGuid().ToString());
values.Add(txtLogin.Text);
values.Add(txtPWD.Text);
values.Add(txtFName.Text);
values.Add(txtLName.Text);
values.Add(txtPhone.Text);
values.Add(txtEmail.Text);
values.Add(0);
if(txtAddr.Text!=String.Empty)
{
values.Add("'" + txtAddr.Text + "'");
}
else
{
values.Add("NULL");
}
if(txtMobile.Text!=String.Empty)
{
values.Add("'" + txtMobile.Text + "'");
}
else
{
values.Add("NULL");
}
if(txtBirth.Text!=String.Empty)
{
values.Add("'"+txtBirth.Text+"'");
}
else
{
values.Add("NULL");
}
sql=String.Format(strBul.ToString(),values.ToArray());
string strConn="Provider=Microsoft.Jet.OleDb.4.0;";
strConn+=@"Data Source=C:\Documents and Settings\Administrator\VSWebCache\BT-CONTROL\FriendsReunion\Data\User.mdb";
OleDbConnection myStrConn=new OleDbConnection(strConn);
myStrConn.Open();
OleDBCom=new OleDbCommand(sql,myStrConn);
bool doredirect=true;
try
{OleDBCom.ExecuteNonQuery();}
catch
{
doredirect=false;
this.LblMessage.Visible=true;
this.LblMessage.Text="Insert couldn't be performed,Username may be aready taken!";
}
finally
{
myStrConn.Close();
}
if(doredirect)
{
Response.Redirect("Login.aspx");
}
}
else
{
LblMessage.Text="Fix the following errors and retry!";
}
}
}
}
最近在学习web编程,请大家帮忙看看哪地方出错了。
我是按照书上面的例题写的,不同之处就是书上用的sql server,而我没有装这个数据库,就改用了Access,编译能通过,但是就不能进行插入操作,请大家帮帮忙啊!!!