Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

369
Views
How to load data from datatable into a resx file?

I have extracted data from database into a datatable. And now i want to add data from this datatable into a resx file. I have created a resx file and datatable like this.

class LoadData
{
public static void main(string[] args)
{
string FilePath=@"C:\"
DataTable dt = new DataTable();
using(ResXResourceWriter rxrw = new ResXResourceWriter(FilePath+"Demo.resx"))
{
SqlConnection conn=new SqlConnection();
conn.ConnectionString="my connection string here";
SqlCommand cmd= new SqlCommand("my sql command here",conn);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
conn.Close;
da.Dispose();
}
}
}

So how can i load data from datatable dt into Demo.resx file?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can do something like

public class Example
{
   public static void Main()
   {
      // Instantiate an Automobile object.
      Automobile car1 = new Automobile("Ford", "Model N", 1906, 0, 4);
      Automobile car2 = new Automobile("Ford", "Model T", 1909, 2, 4);
      // Define a resource file named CarResources.resx.
      using (ResXResourceWriter resx = new ResXResourceWriter(@".\CarResources.resx"))
      {
         resx.AddResource("Title", "Classic American Cars");
         resx.AddResource("HeaderString1", "Make");
         resx.AddResource("HeaderString2", "Model");
         resx.AddResource("HeaderString3", "Year");
         resx.AddResource("HeaderString4", "Doors");
         resx.AddResource("HeaderString5", "Cylinders");
         resx.AddResource("Information", SystemIcons.Information);
         resx.AddResource("EarlyAuto1", car1);
         resx.AddResource("EarlyAuto2", car2);
      }
   }

Refer https://docs.microsoft.com/en-us/dotnet/framework/resources/working-with-resx-files-programmatically

over 4 years ago · Santiago Trujillo Report

0

This answer is not an answer to your question, but a possible solution to what I understood you are looking for (embedding a DataTable in an assembly).

The DataTable could be transformed to XML:

dt.WriteXml(@"c:\myDataTable.xml");

You drag&drop this xml file to your project at the desired location. (e.g. Resources directory)

Right-click on it and select "Embedded resource" as compile action.

Now it's available in your code with such a method:

public DataTable XmlToDataTable(string resourceName = "myDataTable.xml")
{
    DataSet ds = new DataSet();
    using (System.IO.Stream input = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyProject.Resources." + resourceName))
    {
        try
        {
            ds.ReadXml(input);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            return null;
        }
    }
    return ds.Table[0];
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!