Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. adding new data over ProcessLayer

adding new data over ProcessLayer

Scheduled Pinned Locked Moved C#
databasehelp
14 Posts 2 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Erdinc27
    wrote on last edited by
    #1

    hey guys..i try to add datas by stored procedure with 15 parameters..it works well..the problem is in my ProcessLayer..i have Firmalar class like below.

    public class Firmalar
    {
        public string firma\_adi { get; set; }
        public string yetkili1 { get; set; }
        public string gsm1 { get; set; }
        public string email1 { get; set; }
        public string yetkili2 { get; set; }
        public string gsm2 { get; set; }
        public string email2 { get; set; }
        public string yetkili3 { get; set; }
        public string gsm3 { get; set; }
        public string email3 { get; set; }
        public string telefon1 { get; set; }
        public string telefon2 { get; set; }
        public string telefon3 { get; set; }
        public string telefon4 { get; set; }
        public string telefon5 { get; set; }
    }
    

    and i try to add data in my processLayer like that

    public void InsertFirm(Firmalar fir)
    {
    try
    {
    fir = new Firmalar();
    cmmd = d.InsertData();
    cmmd.Parameters.AddWithValue("@firmanin_adi", System.Data.SqlDbType.NVarChar).Value = fir.firma_adi;
    cmmd.Parameters.AddWithValue("@yetkili1", System.Data.SqlDbType.NVarChar).Value = fir.yetkili1;
    cmmd.Parameters.AddWithValue("@gsm_num1", System.Data.SqlDbType.NVarChar).Value = fir.gsm1;
    cmmd.Parameters.AddWithValue("@e_mail1", System.Data.SqlDbType.NVarChar).Value = fir.email1;
    cmmd.Parameters.AddWithValue("@yetkili2", System.Data.SqlDbType.NVarChar).Value = fir.yetkili2;
    cmmd.Parameters.AddWithValue("@gsm_num2", System.Data.SqlDbType.NVarChar).Value = fir.gsm2;
    cmmd.Parameters.AddWithValue("@e_mail2", System.Data.SqlDbType.NVarChar).Value = fir.email2;
    cmmd.Parameters.AddWithValue("@yetkili3", System.Data.SqlDbType.NVarChar).Value = fir.yetkili3;
    cmmd.Parameters.AddWithValue("@gsm_num3", System.Data.SqlDbType.NVarChar).Value = fir.gsm3;
    cmmd.Parameters.AddWithValue("@e_mail3", System.Data.SqlDbType.NVarChar).Value = fir.email3;
    cmmd.Parameters.AddWithValue("@tlfn1", System.Data.SqlDbType.NVarChar).Value = fir.telefon1;
    cmmd.Parameters.AddWithValue("@tlfn2", System.Data.SqlDbType.NVarChar).Value = fir.telefon2;
    cmmd.Parameters.AddWithValue("@tlfn3", System.Data.SqlDbType.NVarChar).Value = fir.telefon3;

    H 1 Reply Last reply
    0
    • E Erdinc27

      hey guys..i try to add datas by stored procedure with 15 parameters..it works well..the problem is in my ProcessLayer..i have Firmalar class like below.

      public class Firmalar
      {
          public string firma\_adi { get; set; }
          public string yetkili1 { get; set; }
          public string gsm1 { get; set; }
          public string email1 { get; set; }
          public string yetkili2 { get; set; }
          public string gsm2 { get; set; }
          public string email2 { get; set; }
          public string yetkili3 { get; set; }
          public string gsm3 { get; set; }
          public string email3 { get; set; }
          public string telefon1 { get; set; }
          public string telefon2 { get; set; }
          public string telefon3 { get; set; }
          public string telefon4 { get; set; }
          public string telefon5 { get; set; }
      }
      

      and i try to add data in my processLayer like that

      public void InsertFirm(Firmalar fir)
      {
      try
      {
      fir = new Firmalar();
      cmmd = d.InsertData();
      cmmd.Parameters.AddWithValue("@firmanin_adi", System.Data.SqlDbType.NVarChar).Value = fir.firma_adi;
      cmmd.Parameters.AddWithValue("@yetkili1", System.Data.SqlDbType.NVarChar).Value = fir.yetkili1;
      cmmd.Parameters.AddWithValue("@gsm_num1", System.Data.SqlDbType.NVarChar).Value = fir.gsm1;
      cmmd.Parameters.AddWithValue("@e_mail1", System.Data.SqlDbType.NVarChar).Value = fir.email1;
      cmmd.Parameters.AddWithValue("@yetkili2", System.Data.SqlDbType.NVarChar).Value = fir.yetkili2;
      cmmd.Parameters.AddWithValue("@gsm_num2", System.Data.SqlDbType.NVarChar).Value = fir.gsm2;
      cmmd.Parameters.AddWithValue("@e_mail2", System.Data.SqlDbType.NVarChar).Value = fir.email2;
      cmmd.Parameters.AddWithValue("@yetkili3", System.Data.SqlDbType.NVarChar).Value = fir.yetkili3;
      cmmd.Parameters.AddWithValue("@gsm_num3", System.Data.SqlDbType.NVarChar).Value = fir.gsm3;
      cmmd.Parameters.AddWithValue("@e_mail3", System.Data.SqlDbType.NVarChar).Value = fir.email3;
      cmmd.Parameters.AddWithValue("@tlfn1", System.Data.SqlDbType.NVarChar).Value = fir.telefon1;
      cmmd.Parameters.AddWithValue("@tlfn2", System.Data.SqlDbType.NVarChar).Value = fir.telefon2;
      cmmd.Parameters.AddWithValue("@tlfn3", System.Data.SqlDbType.NVarChar).Value = fir.telefon3;

      H Offline
      H Offline
      Hiren solanki
      wrote on last edited by
      #2

      erdinc27 wrote:

      fir = new Firmalar();

      Inside method InsertFirm(Firmalar fir) why are you again intializing Object? Use the received object itself.

      Regards, Hiren. Microsoft Dynamics CRM

      My Recent Article: - Way to know which control have raised PostBack[^]

      E 1 Reply Last reply
      0
      • H Hiren solanki

        erdinc27 wrote:

        fir = new Firmalar();

        Inside method InsertFirm(Firmalar fir) why are you again intializing Object? Use the received object itself.

        Regards, Hiren. Microsoft Dynamics CRM

        My Recent Article: - Way to know which control have raised PostBack[^]

        E Offline
        E Offline
        Erdinc27
        wrote on last edited by
        #3

        hey Hiren..thanks for the reply..i changed as u said and now it adds first parameter but not second parameter?? so why it happens ?

        vemedya.com

        H 1 Reply Last reply
        0
        • E Erdinc27

          hey Hiren..thanks for the reply..i changed as u said and now it adds first parameter but not second parameter?? so why it happens ?

          vemedya.com

          H Offline
          H Offline
          Hiren solanki
          wrote on last edited by
          #4

          erdinc27 wrote:

          cmmd.Parameters.AddWithValue("@yetkili1", System.Data.SqlDbType.NVarChar).Value = fir.yetkili1;

          You have used blockquoted way to add parameter with value. But AddWithValue having format of AddWithValue(string Parametername,object value) Your statement must generate compile time error I think, Use Like

          cmmd.Parameters.AddWithValue("@yetkili1",fir.yetkili1);

          Regards, Hiren. Microsoft Dynamics CRM

          My Recent Article: - Way to know which control have raised PostBack[^]

          E 1 Reply Last reply
          0
          • H Hiren solanki

            erdinc27 wrote:

            cmmd.Parameters.AddWithValue("@yetkili1", System.Data.SqlDbType.NVarChar).Value = fir.yetkili1;

            You have used blockquoted way to add parameter with value. But AddWithValue having format of AddWithValue(string Parametername,object value) Your statement must generate compile time error I think, Use Like

            cmmd.Parameters.AddWithValue("@yetkili1",fir.yetkili1);

            Regards, Hiren. Microsoft Dynamics CRM

            My Recent Article: - Way to know which control have raised PostBack[^]

            E Offline
            E Offline
            Erdinc27
            wrote on last edited by
            #5

            i tried as u suggested but still nothing..it gives the same error..what else can be reason for that error ?

            vemedya.com

            H 1 Reply Last reply
            0
            • E Erdinc27

              i tried as u suggested but still nothing..it gives the same error..what else can be reason for that error ?

              vemedya.com

              H Offline
              H Offline
              Hiren solanki
              wrote on last edited by
              #6

              Okey As you have done all suggested things. Now Add one thing and see the magic. After intializing command object which is cmmd, Put a line like.

              cmmd.CommandType = CommandType.StoredProcedure

              Regards, Hiren. Microsoft Dynamics CRM

              My Recent Article: - Way to know which control have raised PostBack[^]

              E 1 Reply Last reply
              0
              • H Hiren solanki

                Okey As you have done all suggested things. Now Add one thing and see the magic. After intializing command object which is cmmd, Put a line like.

                cmmd.CommandType = CommandType.StoredProcedure

                Regards, Hiren. Microsoft Dynamics CRM

                My Recent Article: - Way to know which control have raised PostBack[^]

                E Offline
                E Offline
                Erdinc27
                wrote on last edited by
                #7

                again me..i added the code u said but still no magic :) u have any other suggesstion ?

                vemedya.com

                H 1 Reply Last reply
                0
                • E Erdinc27

                  again me..i added the code u said but still no magic :) u have any other suggesstion ?

                  vemedya.com

                  H Offline
                  H Offline
                  Hiren solanki
                  wrote on last edited by
                  #8

                  I think now you might have some problem with InsertData() Method. Can you show us that method,So that we can have better Idea of a whole scenario.

                  Regards, Hiren. Microsoft Dynamics CRM

                  My Recent Article: - Way to know which control have raised PostBack[^]

                  E 1 Reply Last reply
                  0
                  • H Hiren solanki

                    I think now you might have some problem with InsertData() Method. Can you show us that method,So that we can have better Idea of a whole scenario.

                    Regards, Hiren. Microsoft Dynamics CRM

                    My Recent Article: - Way to know which control have raised PostBack[^]

                    E Offline
                    E Offline
                    Erdinc27
                    wrote on last edited by
                    #9

                    here is my InsertData()method

                    public SqlCommand InsertData()
                    {
                    cmd = new SqlCommand("sp_AddDatas", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    return cmd;
                    }

                    and here is the sp_AddDatas

                    ALTER procedure [dbo].[sp_AddDatas]
                    (
                    @firmanin_adi nvarchar(70),
                    @yetkili1 nvarchar(30),
                    @gsm_num1 nvarchar(20),
                    @e_mail1 nvarchar(30),
                    @yetkili2 nvarchar(30),
                    @gsm_num2 nvarchar(20),
                    @e_mail2 nvarchar(30),
                    @yetkili3 nvarchar(30),
                    @gsm_num3 nvarchar(20),
                    @e_mail3 nvarchar(30),
                    @tlfn1 nvarchar(20),
                    @tlfn2 nvarchar(20),
                    @tlfn3 nvarchar(20),
                    @tlfn4 nvarchar(20),
                    @tlfn5 nvarchar(20)
                    )
                    as
                    BEGIN
                    Insert Into Firmalar(firma_adi,yetkili_ad1,Gsm1,email1,yetkili_ad2,Gsm2,Email2,yetkili_ad3,Gsm3,Email3,Telefon1,Telefon2,Telefon3,Telefon4,Telefon5)Values (@firmanin_adi, @yetkili1,@gsm_num1,@e_mail1,@yetkili2,@gsm_num2,@e_mail2, @yetkili3,@gsm_num3,@e_mail3,@tlfn1,@tlfn2,@tlfn3,@tlfn4,@tlfn5)
                    END

                    vemedya.com

                    H 1 Reply Last reply
                    0
                    • E Erdinc27

                      here is my InsertData()method

                      public SqlCommand InsertData()
                      {
                      cmd = new SqlCommand("sp_AddDatas", con);
                      cmd.CommandType = CommandType.StoredProcedure;
                      return cmd;
                      }

                      and here is the sp_AddDatas

                      ALTER procedure [dbo].[sp_AddDatas]
                      (
                      @firmanin_adi nvarchar(70),
                      @yetkili1 nvarchar(30),
                      @gsm_num1 nvarchar(20),
                      @e_mail1 nvarchar(30),
                      @yetkili2 nvarchar(30),
                      @gsm_num2 nvarchar(20),
                      @e_mail2 nvarchar(30),
                      @yetkili3 nvarchar(30),
                      @gsm_num3 nvarchar(20),
                      @e_mail3 nvarchar(30),
                      @tlfn1 nvarchar(20),
                      @tlfn2 nvarchar(20),
                      @tlfn3 nvarchar(20),
                      @tlfn4 nvarchar(20),
                      @tlfn5 nvarchar(20)
                      )
                      as
                      BEGIN
                      Insert Into Firmalar(firma_adi,yetkili_ad1,Gsm1,email1,yetkili_ad2,Gsm2,Email2,yetkili_ad3,Gsm3,Email3,Telefon1,Telefon2,Telefon3,Telefon4,Telefon5)Values (@firmanin_adi, @yetkili1,@gsm_num1,@e_mail1,@yetkili2,@gsm_num2,@e_mail2, @yetkili3,@gsm_num3,@e_mail3,@tlfn1,@tlfn2,@tlfn3,@tlfn4,@tlfn5)
                      END

                      vemedya.com

                      H Offline
                      H Offline
                      Hiren solanki
                      wrote on last edited by
                      #10

                      Now I don't have any clue but see my answer I have given for THIS[^], and try to give parameters value like that way. And also show us a full error statement to be further analyzing.

                      Regards, Hiren. Microsoft Dynamics CRM

                      My Recent Article: - Way to know which control have raised PostBack[^]

                      E 1 Reply Last reply
                      0
                      • H Hiren solanki

                        Now I don't have any clue but see my answer I have given for THIS[^], and try to give parameters value like that way. And also show us a full error statement to be further analyzing.

                        Regards, Hiren. Microsoft Dynamics CRM

                        My Recent Article: - Way to know which control have raised PostBack[^]

                        E Offline
                        E Offline
                        Erdinc27
                        wrote on last edited by
                        #11

                        hi again..i tried to add values like in the link u sent at that time it given error like "an SqlParameter with parameter name '@firmanin_adi' is not contained by this SqlParameterCollection" in my process layer

                        vemedya.com

                        E 1 Reply Last reply
                        0
                        • E Erdinc27

                          hi again..i tried to add values like in the link u sent at that time it given error like "an SqlParameter with parameter name '@firmanin_adi' is not contained by this SqlParameterCollection" in my process layer

                          vemedya.com

                          E Offline
                          E Offline
                          Erdinc27
                          wrote on last edited by
                          #12

                          hi friend it adds the datas now i changed something more after u offered..thanks for help and one more question; is it too redicilous way to write a method which gets 15 parameters in my process layer and them to call it in my form inside and to assign the parameters here ?

                          vemedya.com

                          H 1 Reply Last reply
                          0
                          • E Erdinc27

                            hi friend it adds the datas now i changed something more after u offered..thanks for help and one more question; is it too redicilous way to write a method which gets 15 parameters in my process layer and them to call it in my form inside and to assign the parameters here ?

                            vemedya.com

                            H Offline
                            H Offline
                            Hiren solanki
                            wrote on last edited by
                            #13

                            That's okey the way you are processing. But Why you have kept a seperate method for InsertData() You should Initialize command there itself. No need for extra garbage. Wrap thing in a function that can be reusable or having something meaning. You got your problem solved now, I have also found why you were getting error let me tell you if you have found the same or different. In your event btnEkle_Click you have called h.InsertFirm(firma); directly without setting value for each property, and after finishing a whole operation you are assigning value, I think you're very much newbie with OOPS. try to read some books around will give you better idea on this.

                            Regards, Hiren. Microsoft Dynamics CRM

                            My Recent Article: - Way to know which control have raised PostBack[^]

                            E 1 Reply Last reply
                            0
                            • H Hiren solanki

                              That's okey the way you are processing. But Why you have kept a seperate method for InsertData() You should Initialize command there itself. No need for extra garbage. Wrap thing in a function that can be reusable or having something meaning. You got your problem solved now, I have also found why you were getting error let me tell you if you have found the same or different. In your event btnEkle_Click you have called h.InsertFirm(firma); directly without setting value for each property, and after finishing a whole operation you are assigning value, I think you're very much newbie with OOPS. try to read some books around will give you better idea on this.

                              Regards, Hiren. Microsoft Dynamics CRM

                              My Recent Article: - Way to know which control have raised PostBack[^]

                              E Offline
                              E Offline
                              Erdinc27
                              wrote on last edited by
                              #14

                              yeah i am new about it really and try to learn it..i hope it doesnt take much time to improve my skills :) thanks for your help again

                              vemedya.com

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups