首页 新闻 搜索 专区 学院

数据操作!!!!!

0
悬赏园豆:5 [已关闭问题] 关闭于 2012-02-24 16:38

怎样讲数据操作写成一个类,要怎么调用,本人是菜鸟,以我附加的代码为例子,尽量详细点!谢谢!!!

View Code
using System;
using System.Collections;
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 reg : System.Web.UI.Page
{
static string connection = "Data Source=PC-201109290903;Initial Catalog=#Home#Malihome@2011;Integrated Security=True";
private SqlConnection sqlConnection1 = new SqlConnection(connection);
private SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter();
private DataSet dataSet11 = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{

}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
//諾帳號文本框內為空
if (username.Text == "")
{
LabelMessage.Text = "<script language='Jscript'>" + "alert('您必須輸入帳號!');</script>";
}
else
{
string number = this.username.Text;
SqlCommand myCommand = this.sqlConnection1.CreateCommand();
myCommand.CommandText = "select * from HTX_Member where username='" + number + "'";
this.sqlDataAdapter1.SelectCommand = myCommand;
dataSet11.Clear();
int n = this.sqlDataAdapter1.Fill(dataSet11, "HTX_Member");
if (n != 0)
LabelMessage.Text = "<script language='Jscript'>" + "alert('您輸入的帳戶號已經被占用,請重新輸入!');</script>";
else
{
LabelMessage.Text = "";
if (userpwd.Text != userpwd1.Text )
LabelMessage.Text = "<script language='Jscript'>" + "alert('密碼與重複密碼不一致,請重新輸入密碼和重複密碼!');</script>";
else
{
LabelMessage.Text = "";
if (useremail.Text != useremail1.Text)
LabelMessage.Text = "<script language='Jscript'>" + "alert('輸入的Email与電郵不一致,請重新輸入!');</script>";
else
{
LabelMessage.Text = "";
}
try
{
myCommand.CommandText = "insert into HTX_Member(username,useremail,userpwd)" + "values(@username,@useremail,@userpwd)";
myCommand.Parameters.Add("@username", SqlDbType.NVarChar, 50, "username");
myCommand.Parameters.Add("@useremail", SqlDbType.NVarChar, 50, "useremail");
myCommand.Parameters.Add("@userpwd", SqlDbType.NVarChar, 50, "userpwd");
myCommand.Parameters["@username"].Value = username.Text;
myCommand.Parameters["@useremail"].Value = useremail.Text;
myCommand.Parameters["@userpwd"].Value = userpwd.Text;
sqlConnection1.Open();
myCommand.ExecuteNonQuery();
sqlConnection1.Close();
LabelMessage.Text = "您已經成功註冊!";
}
catch (Exception Exc)
{
LabelMessage.Text = Exc.Message;
sqlConnection1.Close();
}
}

}
}
}
}
as、的主页 as、 | 初学一级 | 园豆:96
提问于:2012-02-24 15:08
< >
分享
所有回答(1)
0

那个,你代码打不开

today4king | 园豆:3299 (老鸟四级) | 2012-02-24 16:34

我关了重开!

支持(0) 反对(0) as、 | 园豆:96 (初学一级) | 2012-02-24 16:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册