C#中的三层数据库

时间:2014-02-22 18:01:06

标签: c#

代码中没有错误,但数据库中没有插入数据

后面是每一层的代码

用户层:

private void btnSave_Click(object sender, EventArgs e)
    {
        EmpProps p = new EmpProps();
        p.Code1 = Convert.ToInt32(tfId.Text);
        p.Name1 = tfName.Text;
        p.Cell1 = tfCell.Text;
        p.Adrs1 = tfAdrs.Text;
        p.Dept1 = cmbDept.Text;
        EmpBll eb = new EmpBll();
        bool b =eb.InsertEmpBll(p);
        if(b)
        { MessageBox.Show("Saved successfully");
        }
        else
        { MessageBox.Show("Error Ocurred");
        }
    }

逻辑层:

public class EmpBll
{
    public bool InsertEmpBll(EmpProps p)
    {
        EmpDal empdal = new EmpDal();
        bool b =empdal.InsrtEmpDal(p);

        if (b)
            return true;
        else
            return false;

    }

}

数据访问层:

public class EmpDal
{
   public bool InsrtEmpDal(EmpProps p)
   {
       SqlConnection conn = new SqlConnection("Data Source=DASTGIRKHAN\\SQLEXPRESS;Initial Catalog=MultilayerManagementSystem;Integrated Security=True;Pooling=False");
       SqlCommand cmd = new SqlCommand("Insert INTO EmployeeRecord Values(" + p.Code1.GetType() + ",'" +p.Name1 + "','" + p.Cell1 + "','" +p.Adrs1 + "','" + p.Dept1 + "')", conn);
       conn.Open();
       int c= cmd.ExecuteNonQuery();
       conn.Close();
       if (c > 0)
           return true;
       else

          return false;
   }
}

0 个答案:

没有答案