Click here to Skip to main content
16,020,626 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
SQL
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
C#
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

C#
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.
C#
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();

    }
Posted
Updated 10-Jul-13 21:36pm
v5
Comments
Maciej Los 10-Jul-13 7:26am    
How can we help you having no information about the structure of database and having no information about method(s) do you use?
Can you answer me?
Please, be more specific and provide more details. Use "Improve question" widget.
Saraa123 10-Jul-13 10:38am    
Thanks. i do that. To tell you the truth i am beginner.
Maciej Los 11-Jul-13 1:56am    
Ok, now is better, but what Save() procedure do?
[EDIT]
In a meanwhile, have a look here: Tutorial 1: Creating Data Access Layer (C#)[^]
[/EDIT]
Saraa123 11-Jul-13 3:40am    
Now i put save method,sorry
You know, address save is okay but the matter is person.
I think that data layer doesn't have a problem ????????
Dholakiya Ankit 10-Jul-13 7:41am    
absolutly right maciej

1 solution

You don't describe briefly your programming structure.
Hope there is a layer data access layer.
Steps
1. Pick the Foreign Keys value from database or front end
2. Set on a person object(view layer)
3.Sent the object on Business logic layer to implement your logic(Business layer )
4.Sent the new object on data access layer(Data access layer).
5.Extract the object and store in database(using store procedure also alternatives)

Hope fully It helps......
Best Regards
 
Share this answer
 
Comments
Saraa123 11-Jul-13 6:56am    
Please see my question again. I update that.
TNX

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900