Click here to Skip to main content
15,908,445 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionSendEmail Pin
Socheat.Net19-Jul-06 22:19
Socheat.Net19-Jul-06 22:19 
AnswerRe: SendEmail Pin
The ANZAC19-Jul-06 22:21
The ANZAC19-Jul-06 22:21 
GeneralRe: SendEmail Pin
Socheat.Net19-Jul-06 22:41
Socheat.Net19-Jul-06 22:41 
GeneralRe: SendEmail Pin
The ANZAC19-Jul-06 23:03
The ANZAC19-Jul-06 23:03 
QuestionProblem in Deployment of VB.Net project Pin
karansharma19-Jul-06 20:25
karansharma19-Jul-06 20:25 
AnswerRe: Problem in Deployment of VB.Net project [modified] Pin
Polymorpher20-Jul-06 5:43
Polymorpher20-Jul-06 5:43 
GeneralRe: Problem in Deployment of VB.Net project Pin
karansharma23-Jul-06 19:50
karansharma23-Jul-06 19:50 
GeneralRe: Problem in Deployment of VB.Net project Pin
Polymorpher24-Jul-06 2:41
Polymorpher24-Jul-06 2:41 
This should help you. Just pass your connection string to new. I have been working on this for a while now. If I am missing any references let me know. I think I made this one pretty much standalone. If you give me your email i will send you this entire component in source code and the dll.

#Region " Imports "
Imports System
Imports System.Data.SqlClient
#End Region

Public Class winConnectionManager

#Region " Variables "
Private m_Conn As SqlConnection
Private m_ConnStr As String
Private m_Valid As Boolean = True
Protected Shared m_ShowErrors As Boolean
#End Region

#Region " Constructor "
Public Sub New(Optional ByVal showErrors As Boolean = True)
Me.New(winAppConfig.GetSetting("SQLString"), showErrors)
End Sub

Public Sub New(ByVal conStr As String, Optional ByVal showErrors As Boolean = True)
Try
m_ShowErrors = showErrors
m_ConnStr = conStr
m_Conn = New SqlConnection(m_ConnStr)
m_Conn.Open()
Catch ex As Exception
m_Valid = False
If m_ShowErrors Then
Throw New Exception(ex.Message & vbCrLf & vbCrLf & " Occured in winConnectionManager::New")
End If
End Try
End Sub
#End Region

#Region " Propertys "
Public ReadOnly Property GetConnection() As SqlConnection
Get
Return m_Conn
End Get
End Property

Public ReadOnly Property GetConnectionString() As String
Get
Return m_ConnStr
End Get
End Property

Public ReadOnly Property Valid() As Boolean
Get
Return m_Valid
End Get
End Property
#End Region

#Region " Public Functions "
Public Function UpdateDataSet(ByVal ds As DataSet, Optional ByVal allowDelete As Boolean = True) As Boolean
Try
If Not m_Valid Then Return False

If Not winDSUtils.IsDSEmpty(ds) Then
If ds.HasChanges Then
Dim tbl As String = ds.Tables(0).TableName
Dim pkField As String = ds.Tables(0).PrimaryKey(0).ColumnName
Dim theInsert As String = Nothing
Dim tryedToDelete As Boolean = False

For Each r As DataRow In ds.GetChanges.Tables(0).Rows
Dim state As DataRowState = r.RowState
Select Case state
Case DataRowState.Added
If theInsert Is Nothing Then theInsert = winSQLUtils.BuildInsertSQL(ds.Tables(0))
r.AcceptChanges()
ExecuteNonQry(theInsert & winSQLUtils.GetInsertValues(r))
Case DataRowState.Deleted
r.RejectChanges()
If allowDelete Then
ExecuteNonQry("Delete From " & tbl & " Where " & pkField & " = " & r.Item(pkField))
r.Delete()
Else : tryedToDelete = True
End If
Case DataRowState.Modified
r.AcceptChanges()
ExecuteNonQry(winSQLUtils.GetUpdateSQL(r))
End Select
Next r
If tryedToDelete Then MsgBox("You are not alowed to delete these items!")
ds.AcceptChanges()
End If
End If
Catch ex As Exception
If m_ShowErrors Then
Throw New Exception(ex.Message & vbCrLf & vbCrLf & " Occured in winConnectionManager::UpdateDataSet")
End If
Return False
End Try
End Function

Public Function InsertDataRowReturnKey(ByVal r As DataRow) As Integer
Try
ExecuteNonQry(winSQLUtils.GetInsertSQL(r))
Return GetLastKey(r.Table.TableName)
Catch ex As Exception
If m_ShowErrors Then
Throw New Exception(ex.Message & vbCrLf & vbCrLf & " Occured in winConnectionManager::InsertDataRowReturnKey")
End If
Return -1
End Try
End Function

Public Function GetLastKey(ByVal tblName As String) As Integer
Try
Return IIf(m_Valid, CInt(ExecuteScaler("SELECT IDENT_CURRENT('" & tblName & "') As ID")), -1)
Catch ex As Exception
If m_ShowErrors Then
Throw New Exception(ex.Message & vbCrLf & vbCrLf & " Occured in winConnectionManager::GetLastKey")
End If
Return -1
End Try
End Function

Public Function ExecuteScaler(ByVal sqlStr As String) As Object
Try
If Not m_Valid Then Return Nothing

Return New SqlCommand(sqlStr, m_Conn).ExecuteScalar()
Catch ex As Exception
If m_ShowErrors Then
Throw New Exception(ex.Message & vbCrLf & vbCrLf & " Occured in winConnectionManager::ExecuteScaler")
End If
Return Nothing
End Try
End Function

Public Function Execute(ByVal sqlStr As String) As DataSet
Try
If Not m_Valid Then Return Nothing

Dim ds As New DataSet
With New SqlDataAdapter(New SqlCommand(sqlStr, m_Conn))
.Fill(ds)
End With

Return ds
Catch ex As Exception
If m_ShowErrors Then
Throw New Exception(ex.Message & vbCrLf & vbCrLf & " Occured in winConnectionManager::Execute")
End If
Return Nothing
End Try
End Function

Public Function ExecuteNonQry(ByVal sqlStr As String) As Integer
Try
IIf(m_Valid, New SqlCommand(sqlStr, m_Conn).ExecuteNonQuery, 0)
Catch ex As Exception
If m_ShowErrors Then
Throw New Exception(ex.Message & vbCrLf & vbCrLf & " Occured in winConnectionManager::ExecuteNonQuery")
End If
Return 0
End Try
End Function

Public Function GetData(ByVal sqlStr As String, ByVal tblName As String) As DataSet
Try
If Not m_Valid Then Return Nothing

Dim ds As New DataSet
With New SqlDataAdapter(New SqlCommand(sqlStr, m_Conn))
.Fill(ds, tblName)
End With

Return ds
Catch ex As Exception
If m_ShowErrors Then
Throw New Exception(ex.Message & vbCrLf & vbCrLf & " Occured in winConnectionManager::GetData")
End If
Return Nothing
End Try
End Function

#Region " DataReader "
Public Function GetDataReader(ByVal sqlStr As String) As SqlDataReader
Try
If Not m_Valid Then Return Nothing

Return New SqlCommand(sqlStr, m_Conn).ExecuteReader
Catch ex As Exception
If m_ShowErrors Then
Throw New Exception(ex.Message & vbCrLf & vbCrLf & " Occured in winConnectionManager::GetDataReader")
End If
Return Nothing
End Try
End Function

Public Function RDR_Execute(ByVal sqlStr As String) As DataSet
Try
If Not m_Valid Then Return Nothing

Return winDataReaderUtils.DataReaderToDataset(GetDataReader(sqlStr))
Catch ex As Exception
If m_ShowErrors Then
Throw New Exception(ex.Message & vbCrLf & vbCrLf & " Occured in winConnectionManager::ExecuteDR")
End If
Return Nothing
End Try
End Function

Public Function RDR_GetData(ByVal sqlStr As String, ByVal tblName As String) As DataSet
Try
If Not m_Valid Then Return Nothing

Return winDataReaderUtils.DataReaderToDataset(GetDataReader(sqlStr), tblName, tblName)
Catch ex As Exception
If m_ShowErrors Then
Throw New Exception(ex.Message & vbCrLf & vbCrLf & " Occured in winConnectionManager::GetData")
End If
Return Nothing
End Try
End Function
#End Region

#End Region

#Region " Overrides "
Protected Overrides Sub Finalize()
Try
m_Conn.Close()
Catch
End Try

m_Conn = Nothing
MyBase.Finalize()
End Sub
#End Region

End Class

Pablo
www.aes4you.com

GeneralRe: Problem in Deployment of VB.Net project Pin
karansharma24-Jul-06 5:22
karansharma24-Jul-06 5:22 
GeneralRe: Problem in Deployment of VB.Net project Pin
Polymorpher24-Jul-06 7:49
Polymorpher24-Jul-06 7:49 
GeneralRe: Problem in Deployment of VB.Net project Pin
karansharma24-Jul-06 18:44
karansharma24-Jul-06 18:44 
GeneralRe: Problem in Deployment of VB.Net project Pin
Polymorpher25-Jul-06 16:45
Polymorpher25-Jul-06 16:45 
GeneralRe: Problem in Deployment of VB.Net project Pin
karansharma25-Jul-06 18:50
karansharma25-Jul-06 18:50 
GeneralRe: Problem in Deployment of VB.Net project Pin
Polymorpher26-Jul-06 2:49
Polymorpher26-Jul-06 2:49 
AnswerRe: Problem in Deployment of VB.Net project Pin
Rizwan Bashir21-Jul-06 5:40
Rizwan Bashir21-Jul-06 5:40 
GeneralRe: Problem in Deployment of VB.Net project Pin
karansharma23-Jul-06 20:01
karansharma23-Jul-06 20:01 
QuestionCreating/Extracting Zip files via code Pin
Serpent66619-Jul-06 20:07
Serpent66619-Jul-06 20:07 
AnswerRe: Creating/Extracting Zip files via code Pin
Rizwan Bashir21-Jul-06 5:42
Rizwan Bashir21-Jul-06 5:42 
GeneralRe: Creating/Extracting Zip files via code Pin
Serpent66621-Jul-06 18:17
Serpent66621-Jul-06 18:17 
QuestionVb to Vb.net Conversion Pin
meeta_tandel19-Jul-06 19:34
meeta_tandel19-Jul-06 19:34 
AnswerRe: Vb to Vb.net Conversion Pin
User 171649220-Jul-06 1:59
professionalUser 171649220-Jul-06 1:59 
Questionsaving item to same location as the program Pin
Serpent66619-Jul-06 18:34
Serpent66619-Jul-06 18:34 
AnswerRe: saving item to same location as the program Pin
nobel@tele.gl19-Jul-06 21:56
nobel@tele.gl19-Jul-06 21:56 
QuestionDownloading file from website using windows form app Pin
rainbowknight19-Jul-06 18:05
rainbowknight19-Jul-06 18:05 
Questionsigning PDF documents with frame work 1.1 Pin
walsudani19-Jul-06 17:58
walsudani19-Jul-06 17:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.