C#对SQLServer中的数据导入导出.pdf数据库RENE& DATABASERows[il[6].ToStringMicrosoft. office. Corecom Parameters []. Value= diExcelRows[il[7]. ToString()(1)com Parameters [J Value= dtRows[i[8].ToString(if (conn State = Connection State Closed(3)Excelonn. Open((4)com. ExecuteNonQuery(Excelconn Close()WindowsMessage Box. Show(EXCELfrmOutputStudent");dgyStudent. Data Source nulldgv Student ReadOnly = tru團导出数据到ECEL□三区catch(Exception ex请选择要导出的班级编号:Message Box. Show十exMessage ToString()□导出退出private void tsbExit_Click(object sender, EventArgs e)this close(s Sheet 1cDExcelToDSClickExcelToDS O3叩口期:200年6月16口星期二一姓名性别民族身份证号出生日期家庭住址家庭电话270206丁玉鹏7073219198842滩诺城r5361346570471汉族371219-3日照营县灯(63528dgvStudent12)070200王松汉族7040519198957枣庄台儿〔5167916:53汉族3702419198972青岛城阳[53287867156连70831191988-6-2济宁3887382722070206田斌男族372921911878骑件单县(5308386971320070206刘女汉族7033195198-107李安肥城5385182汉族3708301951987-6-1(济宁汶上53713792349339Excel12815207200平男1族711190959957270206孙丽女族72926191989-638骑巨野〔5308481582汉族702341919811青岛政南(592818447汉族3707419198810坊安丘53679286版族3709111984-1(安岳[538316( 1) Application ClassApplication Class族37128191928临汁蒙!(591379294107Excel252070206国森饭族370231919891-31青皇内cr2) WorkbookWorkbookApplication ClassExcel(3 WorksheetWorksheetWorkbook(1)Excel1)1 ComboBox(4)Rangeo RangeWorksheet)2 Button“ btnOutput”、Excelbtnexitl”。(2)COMMicrosoft Excel 11.0 Object Libraryusing System. Data SqlClientusing Microsoft Office. Interop. ExcelMicrosoft Office. Interop. Excel2009.17电脑编程技巧与维护45实用第一氵智慧密集using Microsoft Office. Core∥/ Excelprivate void frm Outputstudent_Load (object senderWSCells[ 1, 2]EventArgs e)2WSCells(2, 11cbx ClassNo TeSqlConnection conn new SqlConnection(wS Cells 3, 1=Date Time. Nowconn Connection String =" server=(local)\sqlexpress; ToLongDateString(integrated security=true; database=db_student∥/int rowindex= 5: /SqlDataAdapter da= new SqlDataAdapter ("selectint colindex =1.distinctfrom student, conn)foreach(Data Column dc in dt. ColumnsData Set ds1= new Data Set(if (conn State== Connection State. Closed)S Cells [ rowindex, colindex]= dc Column Nameconn. Opencolindex++da. Fillids1, student)conn Close(int row count dt rows. Countcbx ClassNo Data Source ds 1.Tables("student"int col Count= dt Columns. Countcbx ClassNo. DisplayMemberwS.get_ Range (ws Cells [rowindex+1, 1 ws Cells[row Count rowindex, colCount]). NumberFormatLocal ="private void btnOutput_Click(object sender, EventArgs e) //SqlData Adapter da= new SqlData Adapter("selectforeach(Data Row dr in dt. Rowsfrom student where+cbx ClassNo Textconnirowindex++ / 6System Data. Data Table dt new System. Datacolindex 1Data Table(:foreach(Data Column dc in dt. Columnsint count- da. Fillldtif (count == 0wSCells [rowindex, colindex]= dr [dcColumnName]. ToString()Message Box. Show(colindex ++returnApplication Class acExcel; / ExcelWorkbook wb: /private void btnExit_ Click(object sender, EventArgs e)Worksheet ws;∥ac Excel new Application Class(;this close(ac Excel, Visible= true.if (ac Excel = null5Message Box. Show(EXCELSOL ServerMessage BoxButtons. OK, MessageBoxIcon Information)Visual Studio 2005+SOLreturnServer express2005+ Microsoft Office 20032009-4-16)Wb= acExcel Workbooks Add(true): //Ws= Worksheet)wb Worksheets[ 11∥462009.17电脑编程技巧与维护