vb de sql komutlarını nasıl kullanırız?
veri tabnına baglanı ve sql
Bu başlık kilitlidir. Yeni mesajlar gönderilemez veya mevcut mesajlar düzenlenemez.VB'de sql kullanılmaz. Bir SQL sunucusu (RDMS: Relational Database Management Server) kullanırsınız. VB'de bir veritabanı bağlantısı üzerinden bağlandığınız böyle bir sunucuya, sql sorgularını gönderirsiniz ve sonuç tablolarını da gene bu yoldan alırsınız... VB Database Connection- Veritabanı Bağlantısı konusundaki dökümanlarını inceleyin...
ya hasin yasin,
kardeş ben gene de yanlış bilgi vermeyimde sanırım kullanılıyor ya ben sana haber veririm ok bende zaten onun araştırması üzerindeyim slmlar
Declarations
'Class Module MyDataClass.cls
'General Declarations for class module
Private m_PVD As ADODB.Connection
'General Declarations of a form or Class Module
Private rsData As ADODB.Recordset
'Reference to the DSN-Less Connection Class
Private oData As MyDataClass
Code
'Class Code
Public Function MainDataConnection() As ADODB.Connection
Set MainDataConnection = m_PVD
End Function
Private Sub Class_Initialize()
'Create a DSN-Less connection, this one uses Pervasive WGE 8.10
' however it should work with others
Set m_PVD = New ADODB.Connection
m_PVD.Open "Provider=PervasiveOLEDB.8.10;Data Source=MyData"
'Set the connection's CursorLocation property to adUseClient
'Don't use adUseServer else it won't work!
m_PVD.CursorLocation = adUseClient
End Sub
Private Sub Class_Terminate()
'Kill the connection
m_PVD.Close
Set m_PVD = Nothing
End Sub
'END CLASS CODE
Sub GetRecCount()
'The rest is fairly simple.
Dim strSQL As String
Dim dConn As ADODB.Connection
Set rsData = New ADODB.Recordset
Set oData = New MyDataClass
Set dConn = oData.MainDataConnection
strSQL = "SELECT * FROM FCDSTATSIX, FCDUISTAT WHERE FCTSIXDEX = IDX_COUNT ORDER BY IDX_COUNT"
'Get the records and the record count.
rsData.Open strSQL, dConn,,, adCmdText
For i = 0 To rsData.RecordCount
'Do something useful with records and recordcount
rsData.MoveNext
Next
End Sub
http://www.vbcode.com/asp/showsn.asp?theID=10790 linki budur
Declerations
None
Code
MM_capacity_STRING = "Driver={SQL Server};Server=brisbane;Database=events;Uid=;Pwd="
MM_editConnection = MM_capacity_STRING
set conn_temp = CreateObject("ADODB.Connection")
conn_temp.open = MM_editConnection
set conn = CreateObject("ADODB.Command")
conn.ActiveConnection = MM_editConnection
set rs = Createobject("ADODB.RecordSet")
on error resume next
strComputer = "brisbane"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Security,Backup)}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
("SELECT * FROM Win32_NTLogEvent WHERE Logfile = 'System'")
For Each objEvent in colLoggedEvents
Category = objEvent.Category
Computer_Name = objEvent.ComputerName
Event_Code = objEvent.EventCode
Message = objEvent.Message
Record_Number = objEvent.RecordNumber
Source_Name = objEvent.SourceName
Time_Written = objEvent.TimeWritten
Event_Type = objEvent.type
User = objEvent.User
set rs = Createobject("ADODB.RecordSet")
RoleStr = "insert into logs (logname, computername, eventcode, recordnumber, sourcename, eventtype, writtendate, username, message) values ('System Logs', '" & Computer_Name & "', '" & Event_Code & "', '" & Record_Number & "', '" & Source_Name & "', '" & Event_Type & "', '" & Time_Written & "', '" & User & "', '" & Message & "')"
rs.open RoleStr , conn_temp
rs.close
Next
Set colLoggedEvents = objWMIService.ExecQuery _
("SELECT * FROM Win32_NTLogEvent WHERE Logfile = 'Application'")
For Each objEvent in colLoggedEvents
Category = objEvent.Category
Computer_Name = objEvent.ComputerName
Event_Code = objEvent.EventCode
Message = objEvent.Message
Record_Number = objEvent.RecordNumber
Source_Name = objEvent.SourceName
Time_Written = objEvent.TimeWritten
Event_Type = objEvent.type
User = objEvent.User
set rs = Createobject("ADODB.RecordSet")
RoleStr = "insert into logs (logname, computername, eventcode, recordnumber, sourcename, eventtype, writtendate, username, message) values ('Application Logs', '" & Computer_Name & "', '" & Event_Code & "', '" & Record_Number & "', '" & Source_Name & "', '" & Event_Type & "', '" & Time_Written & "', '" & User & "', '" & Message & "')"
rs.open RoleStr , conn_temp
rs.close
Next
Set colLoggedEvents = objWMIService.ExecQuery _
("SELECT * FROM Win32_NTLogEvent WHERE Logfile = 'Security'")
For Each objEvent in colLoggedEvents
Category = objEvent.Category
Computer_Name = objEvent.ComputerName
Event_Code = objEvent.EventCode
Message = objEvent.Message
Record_Number = objEvent.RecordNumber
Source_Name = objEvent.SourceName
Time_Written = objEvent.TimeWritten
Event_Type = objEvent.type
User = objEvent.User
entry = "Security Log^ " & Computer_Name & "^ " & Event_Code & "^ " & Record_Number & "^ " & Source_Name & "^ " & Event_Type & "^ " & Time_Written & "^ " & User & Message & ";"
set rs = Createobject("ADODB.RecordSet")
RoleStr = "insert into logs (logname, computername, eventcode, recordnumber, sourcename, eventtype, writtendate, username, message) values ('Security Logs', '" & Computer_Name & "', '" & Event_Code & "', '" & Record_Number & "', '" & Source_Name & "', '" & Event_Type & "', '" & Time_Written & "', '" & User & "', '" & Message & "')"
rs.open RoleStr , conn_temp
rs.Close
Next
set LogFileSet = GetObject("winmgmts:{impersonationLevel= impersonate,(Security,Backup)}").ExecQuery("select * from Win32_NTEventLogFile where " & "LogfileName='Application' OR LogfileName='System' OR LogfileName='Security'")
dim sBackupName, sMessage
for each Logfile in LogFileSet
sMessage = "Log: " & Logfile.LogfileName & chr(13)
sBackupName = "C:\Temp\" & Logfile.LogfileName & ".log"
sMessage = sMessage & "Backup File: " & sBackupName & chr(13)
RetVal = LogFile.BackupEventlog(sBackupName)
if RetVal = 0 then sMessage = sMessage & "Log backed up" & chr(13)
RetVal = LogFile.ClearEventlog()
if RetVal = 0 then sMessage = sMessage &"Log Cleared"
Next