I have Form
like this
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.
How to code this one? I'm already confused. Thank you before