其实ASP.NET中 WEB调用数据库的方法和在c#桌面应用上一样
下面是我做的登陆注册的代码 大家可以参考一下
protected void btnClick(object sender, EventArgs e)
{
if (this.yong.Value=="")
{
Response.Write("请输入用户名");
}
else
{
if (this.mi2.Value==mi1.Value)
{
if (Radio1.Checked)
{
if (File1.Value=="")
{
Response.Write ("请上传头像");
}
else
{
string s1 = yong.Value;
string s2 = mi1.Value;
string str = "insert into yonghu3(yonghu,mima)VALUES('" + s1 + "','" + s2 + "')";
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=刘宁-PC;Integrated Security=true; Initial Catalog=liaotian";
SqlCommand cmd = new SqlCommand(str, con);
con.Open();
SqlDataReader myreader;
myreader = cmd.ExecuteReader();
Response.Write("注册成功");
con.Close();
}
}
else
{
Response.Write("选择你的性别");
}
}
else
{
Response.Write("密码输入不一致");
}
}