2011-02-15 17 views
0

我從http://opendb.lightspeedsystems.com/contentupdate/database.htm下載了一個數據庫,這是一個zip壓縮文件。無論如何,我的問題是,有兩個文件:virussignatures.datvirussignatures.fmt。我聽說我應該使用BCP將數據庫提取爲SQL。的virussignatures.fmt內容是:在.fmt的幫助下將.dat導出到Xml或可讀的文件

8.0 
11 
1 SQLCHAR  2 64  "~~~~~"   1  VirusName SQL_Latin1_General_CP1_CI_AS 
2 SQLCHAR  2 32  "~~~~~"   2  VirusType   SQL_Latin1_General_CP1_CI_AS 
3 SQLCHAR  2 32  "~~~~~"   3  AppSig    SQL_Latin1_General_CP1_CI_AS 
4 SQLINT  0 4  "~~~~~"   4  SigStart   "" 
5 SQLINT  0 4  "~~~~~"   5  SigEnd    "" 
6 SQLCHAR  2 1024 "~~~~~"   6  Signature   SQL_Latin1_General_CP1_CI_AS 
7 SQLBIT  1 1  "~~~~~"   7  Test    "" 
8 SQLINT  0 4  "~~~~~"   8  CategoryNumber  "" 
9 SQLINT  0 4  "~~~~~"   9  SourceNumber  "" 
10 SQLDATETIME 0 8  "~~~~~"   10 TransactionTime  "" 
11 SQLCHAR  2 50  ""     11 KBID    SQL_Latin1_General_CP1_CI_AS 

我想給virussignatures.dat轉向XML或可以理解的TXT。

這可以使用Vb.Net來完成嗎?如果是這樣如何?無論如何,如果不這樣做應該怎麼做?

回答

1

記下你的sqlserver數據庫的位置(本地或服務器上)。我假設當地。如果您還沒有安裝SqlServer,請下載SqlExpress。該版本確實需要client tools

創建一個數據庫,如果你沒有一個,我認爲它被稱爲virussignatures。

在您的本地SQL數據庫創建此表(在查詢窗口在您的(新)數據庫中運行它)

CREATE TABLE [dbo].[Virusses](
    VirusName nvarchar(64) NULL, 
    VirusType nvarchar(32) NULL, 
    AppSig nvarchar(32) NULL, 
    SigStart int NULL, 
    SigEnd int NULL, 
    Signature nvarchar(1024) null, 
    Test bit null, 
    CategoryNumber int null, 
    SourceNumber int null, 
    TransactionTime Datetime null, 
    KBID nvarchar(50) 
); 
GO 

導入數據

bcp virussignatures.dbo.Virusses in virussignatures.dat -f virussignatures.fmt -T -S . 

讀:http://msdn.microsoft.com/en-us/library/ms162802.aspx

或者或者從一個新的查詢(在sql管理工作室中單擊你的數據庫)

BULK INSERT 
    Virusses 
     FROM 'c:\where\ever\your\file\is\virussignatures.dat' 
     WITH 
     (FORMATFILE = 'c:\where\ever\your\file\is\virussignatures.fmt'); 
GO 

現在,您已經準備好基於此c#示例編寫vb程序來讀取DataSet中的表並通過在VB.NET程序中實現以下代碼來調用WriteXml。

SqlCommand command = new SqlCommand(); 
command.CommandText = "SELECT * FROM Virussignature"; 
command.CommandType = CommandType.Text; 
command.Connection = new SqlConnection("Your conect string here"); 
SqlDataAdapter da = new SqlDataAdapter(command); 
DataSet ds = new DataSet(); 
da.Fill(ds, "Virussignature"); 
StreamWriter xmlDoc = new StreamWriter("virus.xml"); 
ds.WriteXml(xmlDoc); 
xmlDoc.Close();