Imports System.Data
Imports
System.Data.SqlClient
Imports
System.Windows.Forms
Module [Global]
''----------------------------------------------------------------------------------------------------
Public
Const scon As String = "Data Source=servername8;Initial Catalog=databasename;" & _
"Persist Security Info=True;User ID=SA;Password=Welcome"
"Persist Security Info=True;User ID=SA;Password=Welcome"
Public struser As String = "ADMIN"
Public ssql As String
Public
strtem As String
Public
inttem As Integer
Public
blntemp As Boolean
Public
dttable As DataTable
Public
dtset As New DataSet()
Public
dataAdapt As New SqlDataAdapter()
Public sqlConnection As SqlConnection = New SqlConnection(scon)
Public sqlcmd As SqlCommand
''----------------------------------------------------------------------------------------------------
Public
Function dsdttable(ByVal sql As String)
Try
dttable = Nothing
Using conn As New SqlConnection(scon)
Using comm As New SqlCommand()
With comm
.Connection =
conn
.CommandType = CommandType.Text
.CommandText = sql
Try
conn.Open()
dataAdapt.SelectCommand = comm
dtset.Dispose()
dtset.Tables.Clear()
dataAdapt.Fill(dtset)
dataAdapt.Dispose()
comm.Dispose()
conn.Close()
dttable
= dtset.Tables(0)
dtset.Dispose()
Return dttable
Catch ex As
Exception
MessageBox.Show(ex.Message.ToString(), "Error Message")
End Try
End With
End Using
End Using
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End
Function
''----------------------------------------------------------------------------------------------------
Public
Function ExecuteSql(ByVal sql As String) As Boolean
Try
Using conn As New SqlConnection(scon)
Using comm As New SqlCommand()
With comm
.Connection =
conn
.CommandType =
CommandType.Text
.CommandText = sql
End With
Try
conn.Open()
comm.ExecuteNonQuery()
conn.Close()
Return True
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Error Message")
End Try
End Using
End Using
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
End
Function
''----------------------------------------------------------------------------------------------------
Public Function cConOpen() As Boolean
Try
If ConnectionState.Open = True Then
sqlConnection.Close()
sqlConnection.Open()
Return True
Else
sqlConnection.Open()
Return True
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function
''----------------------------------------------------------------------------------------------------
''----------------------------------------------------------------------------------------------------
End Module
No comments:
Post a Comment