Hi
I have a problem. I have a project with 3 layers. I use Ado. In a person table I have 3 foreign keys. nothing happens when i want to insert data from asp Form to sql
my data base and procedures are ready.
that's my data layer
public class Data
{
public Data()
{
Connection1 = new SqlConnection("server=.; database=LLLL; Trusted_Connection=True");
Command1 = Connection1.CreateCommand();
Command1.CommandType = CommandType.StoredProcedure;
}
public SqlConnection Connection1 { get; private set; }
public SqlCommand Command1 { get; set; }
}
save method
public void Save()
{
Data dl= new Data();
dl.Command1.CommandType = CommandType.StoredProcedure;
dl.Command1.CommandText = this.GetType().Name + "_Save";
foreach(PropertyInfo propertyinfo in this.GetType().GetProperties())
{
if (propertyinfo.Name != "Message")
{
dl.Command1.Parameters.Add(new SqlParameter("@"+(propertyinfo.Name), propertyinfo.GetValue(this,null)));
}
}
try
{
dl.Connection1.Open();
dl.Command1.ExecuteNonQuery();
this.Message = "Save id done successfully";
}
catch (SqlException ex)
{
this.Message = ex.Message;
}
finally
{
if (dl.Connection1.State == ConnectionState.Open)
{
dl.Connection1.Close();
}
}
}
and this is the constructor of person in BLL
public Person(int id, string firstname, string lastname, string fathername,
string nationalcode, string birthdate, int genderId, int eduDegreeId,
int addressId, string tel, string mobile, string email)
{
Id = id;
FirstName = firstname;
LastName = lastname;
FatherName = fathername;
NCode = nationalcode;
BirthDate = birthdate;
GenderId = genderId;
DegreeId = eduDegreeId;
AddressId = addressId;
Phone = tel;
Mobile = mobile;
Email = email;
}
and i wrote the save method in Bll.when i want to insert data from presentation layer to SQL nothing happens in person table.
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
var address = new Address(-1, PrvTxt.Text, CitTxt.Text, AvnTxt.Text, StrTxt.Text, NumTxt.Text, FlrTxt.Text);
var person = new Person(-1, NamTxt.Text, FmlTxt.Text, DadTxt.Text, NcdTxt.Text, BrdTxt.Text,
Convert.ToInt32(GenderRadioBtnList.SelectedItem.Value), Convert.ToInt32(EduDropDownList.SelectedItem.Value),
-1, PhnTxt.Text, CphTxt.Text, EmlTxt.Text);
address.Save();
person.Save();
}