asp.net 数据库插入代码
using System;using System.Data;
using System.Configuration;
using System.Collections;
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.OleDb;
public partial class reg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string username = TextBox1.Text.ToString().Trim();
string password = TextBox2.Text.ToString().Trim();
string repaw = TextBox3.Text.ToString().Trim();
string sql = "select * from [user] where username = '" + username + "' ";
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source= " + Server.MapPath("userinfo.mdb");
conn.Open();
string comm2 = "insert into [user] (username,password) VILUES ('" + username + "','" + password + "') ";
OleDbCommand comm = new OleDbCommand(sql, conn);
OleDbDataReader dr = comm.ExecuteReader();
if (username == "" | password == "")
{
Response.Write("账号,密码不能为空!");
}
else
{
if (repaw != password)
{
Response.Write("两次密码输入不匹配!");
}
else
{
if (dr.Read())
{
Response.Write("" + username + "这个用户名已被注册!");
}
else
{
OleDbCommand comm3 = new OleDbCommand(comm2, conn);
Response.Write("注册成功!!");
conn.Close();
}
}
}
}
}
在数据库插入数据时,最后能完成编译,但是没有结果,也就是数据库里没有插入数据进去!
代码如上!!本人分不多!!希望有朋友帮忙解决下!