刚开始做的时候是可以的,后来也不知道咋会事就是运行不了!
首先 “添加”按钮事件是这么写的:
Code
protected void btnAdd_Click(object sender, EventArgs e)
{
//
LinkAdminBbs lab = new LinkAdminBbs();
lab.Busername = this.txtBuserName.Text;
lab.Busertel = this.txtBuserTel.Text;
lab.Buserct = this.txtBuserCt.Text;
if (this.rbtBuserNan.Checked)
{
lab.Busersex = "男";
}
else
{
lab.Busersex = "女";
}
if(txtBuserName.Text.Trim()==""||txtBuserTel.Text.Trim()=="")
{
this.Label1.Text="<font color=red>-_-提交失败!麻烦您!认真填写!</font>";
}
else
{
if (LinAdminBbsOperate.InsertOperater(lab))
{
this.Label1.Text="<font color=green >^_^提交成功!谢谢支持!您的反馈我们已经收到!</font>";
txtBuserName.Text = "";
txtBuserTel.Text = "";
txtBuserCt.Text = "";
}
else
{
Response.Write("F");
}
}
}
我的插入类是独立的:
Code
public class LinAdminBbsOperate
{
public LinAdminBbsOperate()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
////////////////定义插入类//////////////////////
public static bool InsertOperater(LinkAdminBbs LAB)
{
try
{
SqlConnection con = DBAccess.createsqlcon();
con.Open();
SqlCommand cmd = new SqlCommand("insert into BBS (Bname,Bsex,Btel,Bct) values(@Bname,@Bsex,@Btel,@Bct)", con);
SqlParameter para = new SqlParameter("@Bname", SqlDbType.NVarChar, 8);
para.Value = LAB.Busername;
cmd.Parameters.Add(para);
para = new SqlParameter("@Bsex", SqlDbType.NVarChar, 2);
para.Value = LAB.Busersex;
cmd.Parameters.Add(para);
para = new SqlParameter("@Btel", SqlDbType.NVarChar, 20);
para.Value = LAB.Busertel;
cmd.Parameters.Add(para);
para = new SqlParameter("@Bct", SqlDbType.NVarChar, 100);
para.Value = LAB.Buserct;
cmd.Parameters.Add(para);
//执行
cmd.ExecuteNonQuery();
return true;
}
catch (Exception e)
{
return false;
}
}
实体类:
Code
public class LinkAdminBbs
{
/// <summary>
/////////////////////////留言板////////.
//定义实体
/// </summary>
public string Busername;
public string Busertel;
public string Buserct;
public string Busersex;
public LinkAdminBbs()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
}
那位高人帮帮我啊!周六上交毕业设计呢!现在还没写出来!