编写小九九:
protected void Page_Load(object sender, EventArgs e)
{
HtmlTable table = new HtmlTable();
for (int i = 1; i <= 9; i++)
{
HtmlTableRow row = new HtmlTableRow();
for (int j = 1; j <=i; j++)
{
HtmlTableCell cell = new HtmlTableCell();
cell.InnerText = j + "*" + i + "=" + j * i;
row.Cells.Add(cell);
}
table.Rows.Add(row);
}
table.Width = "100%";
table.CellSpacing = 0;
table.CellPadding = 10;
table.Border = 1;
table.BorderColor = "#000000";
this.p1.Controls.Add(table);
}
注册:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnTClick(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=张海涛;integrated Security=true;Initial Catalog=ASP.NET注册";
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
string a;
if (Radio1.Checked)
{
a = "男";
}
else
{
a = "女";
}
string filename=File1.PostedFile.FileName;
filename=DateTime.Now.Ticks.ToString()+filename.Substring(filename.LastIndexOf("."));
//this.File1.PostedFile.SaveAs(Server.MapPath("upload")+"\\"+fillname);
this.File1.PostedFile.SaveAs(Server.MapPath("upload")+"\\"+filename);
cmd.CommandText = "insert into Login(Name,Sex,Password,Image) values ('" + this.name.Value + "','" + a + "','" + this.Password1.Value + "','" + filename + "')";
SqlDataReader myreader = cmd.ExecuteReader();
con.Close();
this.Response.Write("注册成功");
//StringBuilder sb = new StringBuilder();
//sb.Append("用户名是:").Append(this.name.Value);
//sb.Append("<br/>");
//sb.Append("密码是:").Append(this.Password1.Value);
//sb.Append("<br/>");
//sb.Append("性别是:");
//if (Radio1.Checked)
//{
// sb.Append("男");
//}
//else
//{
// sb.Append("女");
//}
//sb.Append("<br/>");
//string fillname=this.File1.PostedFile.FileName;
//fillname=DateTime.Now.Ticks.ToString()+fillname.Substring(fillname.LastIndexOf("."));
//this.File1.PostedFile.SaveAs(Server.MapPath("upload")+"\\"+fillname);
//sb.Append("头像:");
//sb.Append("<img src=\"upload/"+fillname+"\"/>");
//this.divResult.InnerHtml=sb.ToString();
}
}
登陆:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnDClick(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=张海涛;integrated Security=true;Initial Catalog=ASP.NET注册";
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "mp_login3";
SqlParameter Pname = new SqlParameter("@Name", SqlDbType.VarChar, 10, "Name");
Pname.Direction = ParameterDirection.Input;
Pname.Value = this.Text1.Value.Trim();
cmd.Parameters.Add(Pname);
SqlParameter PSex = new SqlParameter("@Sex", SqlDbType.VarChar, 50, "Sex");
PSex.Direction = ParameterDirection.Output;
cmd.Parameters.Add(PSex);
SqlParameter PPassword = new SqlParameter("@Password", SqlDbType.VarChar, 50, "Password");
PPassword.Direction = ParameterDirection.Output;
cmd.Parameters.Add(PPassword);
SqlParameter PImage = new SqlParameter("@Image", SqlDbType.VarChar, 50, "Image");
PImage.Direction = ParameterDirection.Output;
cmd.Parameters.Add(PImage);
conn.Open();
int a = cmd.ExecuteNonQuery();
if (this.Text1.Value == cmd.Parameters["@Name"].Value.ToString().Trim() && this.Text2.Value == cmd.Parameters["@Password"].Value.ToString().Trim())
{
Response.Write("用户名是:" + cmd.Parameters["@Name"].Value.ToString());
Response.Write("性别是:" + cmd.Parameters["@Sex"].Value.ToString());
Response.Write("<img src=\"upload/" + cmd.Parameters["@Image"].Value.ToString() + "\"/>");
//头像是:
}
}
}