I am trying to modify a value in a text file template with a value from a database table without hard coding the relationship between the template field and the database field. I want to use an XML file to hold the names of the placeholders and database field names.
Placeholders look like: [somefieldname]
database fields look like: "databasefieldname"
XML looks like:
Template looks like:
a,b,d,[somefieldname],y,n,1,2, etc...
Is this a crazy thought or is it actually feasible?
Carl CioffiPosted Jun 20, 2013, 10:42 AM
In trying to show you an example of what I am trying to do I solved the problem which was right in front of me but I couldn't see the forest from the trees. I think I was just putting way too much thought into it.
string placeHolder = "[State]";
string fieldName = "cState";
string txtValue = "Y,N,[State],N";
txtValue = txtValue.Replace(placeHolder, row[fieldName].ToString());
Where row is the datatable row with the replacement data.
Sunny SharmaPosted Jun 19, 2013, 10:23 AM
Got your point. Still I've a little to clear related to your text file.
Is it like- a single value from database for every matching placeholder in file, or like a single database value for a single placeholder.
I mean do we have only a single line having the placeholder like:
a,b,d,[somefieldname],y,n,1,2, etc...
or it could be multiple, like:
a,b,d,[somefieldname],y,n,1,2, etc...
a,b,d,[somefieldname],y,n,1,2, etc...
a,b,d,[somefieldname],y,n,1,2, etc...
a,b,d,[somefieldname],y,n,1,2, etc...
OR, alternatively, you just show me your current code, and I'll give you the solution.
Thanks.
Carl CioffiPosted Jun 19, 2013, 8:58 AM
My plan is to move the list of placeholders and the database table fields that replace them into an XML file so when new placeholders are added/removed the code doesn't have to be opened again. We can just modify the XML and go.
9,1,Y,N,[taxrate1],Y,N, etc...
database table field cTaxRate1 replaces [taxrate1] when program executes.
XML data would have
< placeholder>[taxrate1]
< fieldname>cTaxRate1
This would eliminate future code changes when the comma delimited configuration file becomes:
[taxflag],1,Y,N,[taxrate1],Y,N, etc...
Sunny SharmaPosted Jun 19, 2013, 1:52 AM