ÈçºÎ¸ßЧµÄ½«excelµ¼Èësqlserver£¿
´ó²¿·ÖÈ˶¼ÖªµÀÓÃoledbÀ´¶ÁÈ¡Êý¾Ýµ½dataset£¬µ«ÊǶÁÈ¡Ö®ºóÔõô´¦Àídataset¾ÍǧÆæ°Ù¹ÖÁË¡£ºÜ¶àÈËͨ¹ýÑ»·À´Æ´½Ósql£¬ÕâÑù×ö²»µ«ÈÝÒ׳ö´í¶øÇÒЧÂʵÍÏ£¬System.Data.SqlClient.SqlBulkCopy ¶ÔÓÚÐÂÊÖÀ´Ëµ»¹ÊDZȽÏÄ°ÉúµÄ£¬Õâ¸ö¾ÍÊÇ´«ËµÖÐЧÂʼ«¸ßµÄbcp£¬6Íò¶àÊý¾Ý´Óexcelµ¼Èëµ½sqlÖ»ÐèÒª4.5Ãë¡£
using System;
using System.Data;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//²âÊÔ£¬½«excelÖеÄsheet1µ¼Èëµ½sqlserverÖÐ
string connString = "server=localhost;uid=sa;pwd=sqlgis;database=master";
System.Windows.Forms.OpenFileDialog fd = new OpenFileDialog();
if (fd.ShowDialog() == DialogResult.OK)
{
TransferData(fd.FileName, "sheet1", connString);
}
}
Ïà¹ØÎĵµ£º
BULK INSERT
¡¡¡¡ÔÚSQL ServerÖУ¬BULK INSERTÊÇÓÃÀ´½«ÍⲿÎļþÒÔÒ»ÖÖÌض¨µÄ¸ñʽ¼ÓÔص½Êý¾Ý¿â±íµÄT-SQLÃüÁî¡£¸ÃÃüÁîʹ¿ª·¢ÈËÔ±Äܹ»Ö±½Ó½«Êý¾Ý¼ÓÔص½Êý¾Ý¿â±íÖУ¬¶ø²»ÐèҪʹÓÃÀàËÆÓÚIntegration ServicesÕâÑùµÄÍⲿ³ÌÐò¡£ËäÈ»BULK INSERT²»ÔÊÐí°üº¬Èκθ´ÔÓµÄÂß¼»òת»»£¬µ«Äܹ»ÌṩÓë¸ñʽ»¯Ïà¹Øµ ......
package cn.ctgu.edu.ac;
import java.sql.*;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String url="jdbc:sqlserver://localhost:1433;Database=ÍøÉÏÊéµê¹ÜÀíϵͳ;integr ......
1¡¢´´½¨Êý¾Ý¿âtestdb
2¡¢´´½¨±ítest
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[test](
[id] [nchar](10) COLLATE Chinese_PRC_CI_AS NULL,
[name] [nchar](10) COLLATE Chinese_PRC_CI_AS NULL,
[sex] [bit] NULL
) ON [PRIMARY]
3¡¢´´½¨Êý¾Ý¿âdb
......
ÔÚÓëÊý¾Ý¿â´ò½»µÀµÄ¹¤×÷ÖÐʱ³£»áÅöµ½Ò»Ð©Êý¾Ý¿âµÄ´íÎó£¬Õâ¾ÍÉæ¼°µ½ÁËÐÞ¸´µÄ¹ý³Ì£¬ÒÔÏÂ֪ʶµã¶¼ÊÇ´ÓÍøÉÏÊÕ¼¯¶øÀ´:
1¡¢dbcc checkdb
Õâ¸öÃüÁî¿ÖÅÂÊÇÎÒÃÇ×î³£ÓõÄÁË£¬´ø¼ì²éºÍÐÞ¸´¹¦ÄÜ
Óï·¨¸ñʽ£º
DBCC CHECKDB
[
[ ( database_name | database_id | 0
[ , NOINDEX
| , { REPAIR_ALLOW_DATA_LOS ......