0

I have Form like this

My Image

And I have a Class Connect to connect to my database. Here is the code:

class Connect
{
    SqlConnection con;
    public Connect()
    {
        String connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + @"\Database1.mdf;Integrated Security=True;User Instance=True";
        con = new SqlConnection(connectionString);
    }

    public DataTable executeSelect(String query)
    {
        con.Open();
        SqlDataAdapter adapter = new SqlDataAdapter(query, con);
        DataTable dt = new DataTable();
        adapter.Fill(dt);
        con.Close();

        return dt;
    }

    public void execute(String query)
    {

        con.Open();
        SqlCommand cmd = new SqlCommand(query, con);
        cmd.ExecuteNonQuery();

        con.Close();
    }
}

I want to export to Excel from these DataGridView. In Excel file, I want the data position in rows and columns like this(for example): Data from these DataGridView are got from two Tables in Database.

My Excel

How to code this one? I'm already confused. Thank you before

  • try following this link....http://www.aspsnippets.com/Articles/Export-GridView-to-Excel-in-ASPNet-with-Formatting-using-C-and-VBNet.aspx – Siwoku Adeola Jan 11 '16 at 17:17

1 Answers1

0

This is already resolved here and here. Try it and if you still can't, ask a question, there's a difference between asking for help and asking for code

Community
  • 1
  • 1
Rodolfo
  • 247
  • 2
  • 14