ASP.NET 注册、登录与数据的增删改查
刚开始接触ASP.NET 用于自学! 想请教一下用ASP.NET和SQLServer数据库中 数据的关联的一些基本问题
自己做一个网站有用户的注册以及登录,在就是用户在网站中对数据的增删改查!自己不知道该怎么下手
------解决方案--------------------ADO.NET操作
到51aspx.com里下载代码看看
------解决方案--------------------基本流程差不多是这样:
填写信息......信息有效性判断.......数据库操作(查询 添加).....反馈 一个一个步骤来
------解决方案--------------------管理用户的登录/注册等等,这些asp.net提供了一个傻瓜似的解决方案,参考Membership/Login/Profile相关的内容。其实到最后可能觉得除非自己写个Membership API, 大部分的工作就是配置web.config.
CRUD操作可以参考http://asp.net/learn/data-access。
------解决方案--------------------从网上找些例子,看代码
------解决方案-------------------- public void bind(string str)
{
string oledbstr = "";
if (str != null && str != "")
{
oledbstr = str;
}
else
{
oledbstr = "select ID, 姓名,性别,出生日期,工作年限,证件类型,证件号,居住地,Email,手机号码,家庭电话,自我评价 from MResume order by id desc";
}
OleDbConnection oledbcon = new OleDbConnection(GetConnection());
OleDbDataAdapter myda = new OleDbDataAdapter(oledbstr, oledbcon);
DataSet myds = new DataSet();
oledbcon.Open();
myda.Fill(myds, "MResume");
GridView1.DataSource = myds.Tables[0]; //重点要记住的地方,看这个地方是DataSet or DataTable
GridView1.DataKeyNames = new string[] {"id"};//主键
GridView1.DataBind();
oledbcon.Close();
}
GridView行绑定
/// <summary>
/// 改变背景色,第二个方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowDataBound2(object sender, GridViewRowEventArgs e)
{
int i;
//执行循环,保证每条数据都可以更新
for (i = 0; i < GridView1.Rows.Count; i++)
{
//首先判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标停留时更改背景色
// e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
//当鼠标移开时还原背景色
// e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标经过时,行背景色变 00A9FF E6F5FA
// e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#00A9FF'");
//鼠标移出时,行背景色变
// e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
//删除提示操作
((LinkButton)e.Row.Cells[13].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
e.Row.Cells[11].Text = SubStr(e.Row.Cells[11].Text, 20); //用...代替长文本
}