public static int insertcategory(string category_name)
{
SqlConnection myconn = common.Class1.getconn();
string sql = "insert into category([name]) values('"+category_name +"')";
SqlCommand cmd = new SqlCommand(sql,myconn);
myconn.Open ();
int n=cmd.ExecuteNonQuery ();
myconn .Close ();
return n;
}
public static int test()
{
SqlConnection conn = new SqlConnection(@"server=mm-66a9d2040da7;Initial Catalog=News;Integrated Security=True;");
SqlCommand cmd = new SqlCommand("select *from category",conn );
conn.Open();
int n = Convert.ToInt32(cmd .ExecuteNonQuery ());
conn.Close();
return n;
}
public static SqlConnection getconn()
{
SqlConnection conn = new SqlConnection(@"server=mm-66a9d2040da7;Initial Catalog=News;Integrated Security=True;");
return conn;
}
int n = SQLhelp.test();
if (n > 0)
{
Response.Write("Success!");
}
else
{
Response.Write("Failure!");
}
int n=insertcategory(txt_name .Text .ToString ());
if (n > 0)
{ Response.Write("success"); }
else
{ Response.Write("failuer"); }
/*以上为添加新闻类别的代码*/
?如何 添加、修改、删除新闻?
?如何添加评论?
?
?
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(@"server=mm-66a9d2040da7;Initial Catalog=Goods;Integrated Security=True;");
SqlCommand cmd = new SqlCommand("select GoodsID,GoodsIntroduce,GoodsName,GoodsPrice,GoodsPhoto from GoodsInfo where GoodsName like'%"+search_content+"%' or GoodsIntroduce like '%"+search_content+"%'",conn);
conn .Open ();
SqlDataReader sdr = cmd.ExecuteReader();
dt.Load(sdr);
conn .Close ();
return dt;
DataTable dt = this.getinfo(this.txt_name.Text);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
this.databind();
(判断用户名):
ArrayList arr_name = new ArrayList();
arr_name.Add("tianci");
arr_name.Add("weifenng");
foreach (string arr_check in arr_name)
{
if (args.Value == arr_check)
{
Response.Write("<script> alert ('This has been exited ')</script>");
args.IsValid = false;
}
//if (args.Value == "tianci")
//{ Response.Write("<script> alert ('This has been exited ')</script>");
// args.IsValid = false;
public static DataTable getdata()
{
DataTable dt = new DataTable();
SqlConnection myconn = common.SQLhelp.getconn();
string sql = "select * from 人员表";
SqlCommand cmd = new SqlCommand(sql, myconn);
myconn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
dt.Load(sdr);
myconn.Close();
return dt;
}
public static int update(string 部门名称,string 人员编号)
{
SqlConnection myconn = common.SQLhelp.getconn();
string sql = "update 人员表 set 部门名称='"+部门名称+"' where 人员编号='"+人员编号+"'";
SqlCommand cmd = new SqlCommand(sql,myconn );
myconn.Open();
int n = cmd.ExecuteNonQuery();
myconn.Close();
return n;
}
public static DataTable Data()
{
DataTable dt = new DataTable();
SqlConnection myconn = common1.Class1.getconn();
string sql = "select distinct 部门名称 from 人员表";
SqlCommand cmd = new SqlCommand(sql, myconn);
myconn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
dt.Load(sdr);
myconn.Close();
return dt;
}
public class studentDAO
{
public static DataTable getdata(string choose)
{
DataTable dt = new DataTable();
SqlConnection myconn = common1.Class1.getconn();
// string sql = "select * from 人员表 where 部门名称='"+choose+"'or select * from 人员表 where 性别='"+choose+"' select * from 人员表 where 学历='"+choose+"' select * from 人员表 where 技术职称='"+choose+"'";
string sql = "select *from 人员表 where 部门名称 = '"+choose +"' or 性别 ='"+choose +"' or 学历='"+choose +"' or 技术职称='"+choose +"'";
SqlCommand cmd = new SqlCommand(sql,myconn );
myconn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
dt.Load(sdr);
myconn.Close();
return dt;
}
public static DataTable Data()
{
DataTable dt = new DataTable();
SqlConnection myconn = common1.Class1.getconn();
string sql = "select distinct 部门名称 from 人员表";
SqlCommand cmd = new SqlCommand(sql, myconn);
myconn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
dt.Load(sdr);
myconn.Close();
return dt;
}
public static int update(string dep_name,string update_name)
{
SqlConnection myconn = common1.Class1.getconn();
string sl = "update 人员表 set 部门名称='" + update_name + "'where 人员编号='"+dep_name+ "'";
// string sl= " update 人员表 set 部门名称='"+update_name +"' where 人员编号='"+dep_name+"''";
SqlCommand cmd = new SqlCommand(sl,myconn );
myconn.Open();
int n = Convert.ToInt32(cmd .ExecuteNonQuery ());
myconn.Close();
return n;
}
public static DataTable showall()
{
DataTable dt = new DataTable();
SqlConnection myconn = common1.Class1.getconn();
string sql = "select *from 人员表";
SqlCommand cmd = new SqlCommand(sql,myconn );
myconn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
dt.Load(sdr);
myconn.Close();
return dt;
}
}
if (!IsPostBack)
{
databind();
getdata();
getdepname();
getclass(this.dpt_class.SelectedValue.ToString());
}
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string dep_no = this.GridView1.DataKeys[e.RowIndex][1].ToString();
//((TextBox)this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
string dep_name = this.GridView1.DataKeys[e.RowIndex][2].ToString();
//string dep_name = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
string sex=this.GridView1.DataKeys[e.RowIndex][3].ToString();
string age= this.GridView1.DataKeys[e.RowIndex][4].ToString();
string xueli= this.GridView1.DataKeys[e.RowIndex][5].ToString();
//Response.Write("OK");
//人员编号、部门名称
//int n =
DAL1.studentDAO.update(dep_no,dep_name );
Response.Write("部门编号='"+dep_no+"', 部门名称='"+dep_name +"',性别='"+sex+"',年龄='"+age +"',学历='"+xueli+"'");
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
this.GridView1.EditIndex = -1;
this.databind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
this.GridView1.EditIndex = e.NewEditIndex;
this.databind();
}
protected void dpt_class_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void dpt_dep_SelectedIndexChanged(object sender, EventArgs e)
{
this.dpt_class.DataSource = getclass(this .dpt_dep .SelectedValue .ToString ());
this.dpt_class.DataBind();
}
public ArrayList getdepname()
{
ArrayList arr_dep = new ArrayList();
arr_dep.Add("部门名称");
arr_dep.Add("性别");
arr_dep.Add("学历");
arr_dep.Add("技术职称");
return arr_dep;
}
public ArrayList getclass(string s_dep)
{
ArrayList arr_class = new ArrayList();
switch (s_dep)
{
case "部门名称":
arr_class.Add("程序设计部");
arr_class.Add("软件测试部");
arr_class.Add("系统分析部");
break;
case "性别":
arr_class.Add("男");
arr_class.Add("女");
break;
case "学历":
arr_class.Add("本科");
arr_class.Add("大专");
arr_class.Add("研究生");
break;
case "技术职称":
arr_class.Add("技术员");
arr_class.Add("高级技工");
arr_class.Add("高级技师");
break;
default:
arr_class.Add("程序设计部");
break;
}
return arr_class;
}
public void databind()
{
this.GridView1.DataSource = DAL1.studentDAO.getdata(dpt_class.Text .ToString());
this.GridView1.DataBind();
}
public void getdata()
{
this.dpt_dep.DataSource = getdepname();
this.dpt_dep.DataBind();
this.dpt_class.DataSource = getclass(this.dpt_class.SelectedValue .ToString());
this.dpt_class.DataBind();
}
protected void bnt_ok_Click(object sender, EventArgs e)
{
DataTable dt=DAL1.studentDAO.getdata(dpt_class .SelectedValue .ToString ());
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
//getdata();
//this.databind();
}
protected void btn_show_Click(object sender, EventArgs e)
{
DataTable dt = DAL1.studentDAO.showall();
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
//DAL1.studentDAO.showall();
//this.databind();
}