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
Our community of experts have been thoroughly vetted for their expertise and industry experience.