sub test() '定義過程名稱Dim i As Integer, j As Integer, sht As Worksheet 'i,j為整數變數;sht 為excel工作表物件變數,指向某一工作表Dim cn As New ADODB.Connection '定義資料連結對象 ,儲存串連資料庫資訊;請先添加ADO引用Dim rs As New ADODB.Recordset '定義記錄集對象,儲存資料表Dim strCn As String ,strSQL as String '字串
今天剛上班,一個同事找我,說我連不上資料庫了,報錯。此為背景把錯誤貼出來先A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is
System.Data.SqlClient.SqlException: 在與 SQL Server 建立串連時出現與網路相關的或特定於執行個體的錯誤。未找到或無法訪問伺服器。請驗證執行個體名稱是否正確並且 SQL Server 已配置為允許遠端連線。 (provider: 具名管道提供者, error: 40 - 無法開啟到 SQL Server 的串連)解決方案: SQL Server 執行個體上啟用遠端連線1.“開始->所有程式->Microsoft SQL Server 200
--如果是實表可以用if exists (select * from sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[表名]--如果是暫存資料表可以用(說明,如果用尋找實表方法來打暫存資料表會找不到.發布區別對代.)if object_id('tempdb..##temp') is not null drop table #
今天在操作資料庫時,需要將字串轉換成Decimal類型。代碼如下: select cast('0.12' as decimal(18,2)); select convert(decimal(18,2), '0.12'); 當需要將科學計數法的數字字串轉換成Decimal時,這2種寫法都報錯:Msg 8114, Level 16, State 5, Line 1Error converting data type varchar to numeric. select cast('0.12e+006
Group By 子句用於對結果集進行分組,並對每一組資料進行匯總計算。文法格式:Group By [列名] [HAVING 條件運算式]Group By按“列名”指定的列進行分組,將該列列值相同的記錄組成一組,並對每一組進行匯總計算。每一組產生一條記錄。若有“HAVING 條件運算式”,則表示對產生的組進行篩選。 假如,TableX 表包含:--------------------------------ColumnA ColumnB ColumnC1 abc