troubleshooting Question

Can i make the No of fields in a GetObject Method any no of items

Avatar of Olukayode Oluwole
Olukayode OluwoleFlag for Canada asked on
* StoredProcedure.NET ProgrammingC#
4 Comments1 Solution17 ViewsLast Modified:
I have in my c# application a need to write into a postgresql database

I use a simple GetObject method shown below

[code]private void WriteRecord()
        {
            var p = GetObject(LocationIDValue.Text, LocDescriptionValue.Text, LoginDetails.staticcompany, Convert.ToInt32(idValue.Text), LoginDetails.staticinsertupdatedeletetag);
            NewDataAccess.WriteData("public.splocationcode_updateinsert", p);
        }[/code]

It takes fields value from the screen passes them to GetObject method to define
parameters before  using these to write in to my postgresql database

The GetObject Method is shown below

       []public static object GetObject(string parameter01, string parameter02, string parameter03, int parameter04, string parameter05)
        {
           
           
            return new
               {
                    locationidx = parameter01,
                    locdescriptionx = parameter02,
                    companycodex = parameter03,
                    idx = parameter04,
                    dowhatx = parameter05

               };
         
        }[/code]

The applications works fine for this Table with 5  fields

The problem i now have is if i have to address  writing to another table with fields more or less than 5 fields.
Do I have to provide a  GetObject method with the no of parameters equal to the no of fields in that Table.. If Yes will i have to do this for every table in my application ??

Is there a way to make the no of items in the GetObject method have any no of fields.

I was thinking of checking the GetObject Method into a library and then pass the no of fields as  string  and the parameters   as a Datatable

I just dont know if my thinking  is right or if there is another way to achieve the same goal of using the GetObject method to address  2 tables with different no of fields

I will be grateful for any suggestion.

Olukay




ASKER CERTIFIED SOLUTION
ste5an
Senior Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 4 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 4 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004