我们这周的项目是用asp.net做仿京东购物网,通过这两天做项目有了一下收货,下面就分享一下:
验证码生成,删除,插入,update,动态生成ul的函数 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web.UI.HtmlControls;
using System.IO;
/// <summary>
///Class1 的摘要说明
/// </summary>
public class Class1
{
public Class1()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public static readonly string cnnstring = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
public static object executenum(string sqltext,params SqlParameter[] parass)
{
using (SqlConnection con=new SqlConnection(cnnstring))
{
using (SqlCommand cmd=new SqlCommand(sqltext,con))
{
con.Open();
Addcmd(parass, cmd);
return cmd.ExecuteNonQuery();
}
}
} //这时是执行增删改的操作
private static void Addcmd(SqlParameter[] parass, SqlCommand cmd)
{
foreach (SqlParameter item in parass)
{
cmd.Parameters.Add(item);
}
} //这里是添加命令的参数
public static DataTable executetable(string sqltext,params SqlParameter[] parass)
{
using (SqlConnection con = new SqlConnection(cnnstring))
{
using (SqlCommand cmd = new SqlCommand(sqltext, con))
{
con.Open();
Addcmd(parass, cmd);
using (SqlDataReader myreader=cmd.ExecuteReader())
{
DataTable table = new DataTable();
table.Clear();
table.Load(myreader);
return table;
}
}
}