Archive for November 9, 2011

sql backup & restore database to a different db

to backup “testdb1″ db:

backup database testdb1 to disk='c:\bck1'
go

to restore filelist from backup file:
restore filelistonly from disk='c:\bck1''
go

the operation returns the filelist:
testdb1
testdb1_log

to restore db to testdb2
restore database prova3 from disk='c:\bck1'
with recovery,
move 'testdb1' to 'c:\destination\testdb2dat.mdf',
move 'testdb1_log' to 'c:\destionation\testdb2log.ldf'
go

November 9, 2011 at 3:37 pm Leave a comment

Come leggere i nomi dei campi di una tabella senza conoscerli! VB6

Ho una tabella, ma non so il nome dei suoi campi. Come fare?
Vado su google
Digito
adodb.recordset vb6 select get field names

spulcio i risultati
mi imbatto in

http://visualbasic.ittoolbox.com/groups/technical-functional/visualbasic-l/how-to-get-recordset-field-name-877933

tra i commenti trovo il codice

Sub ShowFieldsInfo()
Dim rs As New ADODB.Recordset

Dim i As Integer

‘Error handler
On Error GoTo ShowFields_Error

rs.Open “Select * from Routines;”, CurrentProject.Connection
‘get Field Info
For i = 0 To rs.Fields.Count – 1
‘Add textboxes and labels and position and unhide them here
‘lblLabel.Caption= rs.Fields(i).Name
‘Just for example
Debug.Print “Field ” & i & ” = ” & rs.Fields(i).Name & _
” Type = ” & FieldTypes(rs.Fields(i).Type) & _
” Defined Size =” & rs.Fields(i).DefinedSize
Next
‘Get Field data. Silly as you would only collect these one at a time for
display
Do While Not rs.BOF And Not rs.EOF
For i = 0 To rs.Fields.Count – 1
‘txtBox(i)= rs.Fields(i).Value
Debug.Print rs.Fields(i).Name & ” = ” & rs.Fields(i).Value
Next
rs.MoveNext
Loop
ShowFields_Exit:
‘All final code here
On Error Resume Next
rs.Close
Set rs = Nothing
On Error GoTo 0
Exit Sub

ShowFields_Error:
‘Report error and continue with cleanup for block
MsgBox “Error ” & Err.Number & _
” (” & Err.Description & “) in procedure ShowFields of Module
Module1″
Resume ShowFields_Exit

End Sub

Function FieldTypes(FieldType As Integer) As String
Select Case FieldType
Case AdArray: FieldTypes = “AdArray” ’0×2000
Case adBigInt: FieldTypes = “adBigInt” ’20
Case adBinary: FieldTypes = “adBinary” ’128
Case adBoolean: FieldTypes = “adBoolean” ’11
Case adBSTR: FieldTypes = “adBSTR” ’8
Case adChapter: FieldTypes = “adChapter” ’136
Case adChar: FieldTypes = “adChar” ’129
Case adCurrency: FieldTypes = “adCurrency” ’6
Case adDate: FieldTypes = “adDate” ’7
Case adDBDate: FieldTypes = “adDBDate” ’133
Case adDBTime: FieldTypes = “adDBTime” ’134
Case adDBTimeStamp: FieldTypes = “adDBTimeStamp” ’135
Case adDecimal: FieldTypes = “adDecimal” ’14
Case adDouble: FieldTypes = “adDouble” ’5
Case adEmpty: FieldTypes = “adEmpty” ’0
Case adError: FieldTypes = “adError” ’10
Case adFileTime: FieldTypes = “adFileTime” ’64
Case adGUID: FieldTypes = “adGUID” ’72
Case adIDispatch: FieldTypes = “adIDispatch” ’9
Case adInteger: FieldTypes = “adInteger” ’3
Case adIUnknown: FieldTypes = “adIUnknown” ’13
Case adLongVarBinary: FieldTypes = “adLongVarBinary” ’205
Case adLongVarChar: FieldTypes = “adLongVarChar” ’201
Case adLongVarWChar: FieldTypes = “adLongVarWChar” ’203
Case adNumeric: FieldTypes = “adNumeric” ’131
Case adPropVariant: FieldTypes = “adPropVariant” ’138
Case adSingle: FieldTypes = “adSingle” ’4
Case adSmallInt: FieldTypes = “adSmallInt” ’2
Case adTinyInt: FieldTypes = “adTinyInt” ’16
Case adUnsignedBigInt: FieldTypes = “adUnsignedBigInt” ’21
Case adUnsignedInt: FieldTypes = “adUnsignedInt” ’19
Case adUnsignedSmallInt: FieldTypes = “adUnsignedSmallInt” ’18
Case adUnsignedTinyInt: FieldTypes = “adUnsignedTinyInt” ’17
Case adUserDefined: FieldTypes = “adUserDefined” ’132
Case adVarBinary: FieldTypes = “adVarBinary” ’204
Case adVarChar: FieldTypes = “adVarChar” ’200
Case adVariant: FieldTypes = “adVariant” ’12
Case adVarNumeric: FieldTypes = “adVarNumeric” ’139
Case adVarWChar: FieldTypes = “adVarWChar” ’202
Case adWChar: FieldTypes = “adWChar” ’130
Case Else: FieldTypes = “Undefined”
End Select
End Function

Modifico la query, e funziona tutto!
Bene

November 9, 2011 at 1:19 pm Leave a comment


Calendar

November 2011
M T W T F S S
« Oct    
 123456
78910111213
14151617181920
21222324252627
282930  

Posts by Month

Posts by Category


Follow

Get every new post delivered to your Inbox.