![]() ![]() WS = (Excel.Worksheet)WB.Worksheets.get_Item(1) įor (i = 0 i <= dataGridView1.RowCount - 2 i )įor (j = 0 j <= dataGridView1.ColumnCount - 1 j ) Private void exportoexcel(object sender, EventArgs e) ("test", "excel data") ĭataGridView1.DataSource = DtSet.test ![]() ![]() Mycon = new Source='c:\test.xls' Extended Properties=Excel 8.0 ") Input: private void button1_Click(object sender, EventArgs e) Populating a data grid from excel and export a data grid to excel Using (Streamwtr wtr = new Streamwtr("C:\\op.txt",false)) OleDbCommand command1=new OleDbCommand() Ĭommand1.ctxt="SELECT FirstName, LastName, Phone, City FROM ptable" Ĭommand1.Connection=this.oleDbConnection1 Writing Output of Data grid to a text file This data set is then bounded to the grid view. Then this result is filled in the data set. Then a data adapter is created, which will run the query and get the results. Next is defining the query that needs to be executed on the table. The initial catalog denotes the database name and integrated security denotes windows authentication. The above is the sample code to fetch information from the sql database table and bind it to a data grid view.Īs you can see, the first line contains the sql server information. SqlDataAdapter dt = new SqlDataAdapter(qu, cx) SqlConnection cx = new SqlConnection(sqlconstr) Initial Catalog=Test Integrated Security=True" Connect to SQL Database Table and Display Information ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |