Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

370
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda