Sujeesh ck

Sujeesh ck

  • 1.2k
  • 495
  • 5.5k

How to create SQL Data Layer in Vb.net using the WCF service

Nov 23 2018 2:26 PM
How To  implement the below mentioned Class using WCF  Service. I have tried, but not able to complete with constructor method.
 
Please advice me... Thanks 
 
 
Public Class DBLayer
 
Private SQLConnection As SqlConnection
Private SQLCommand As SqlCommand
Public Exception As Exception
Public Sub New(connectionString As String, Optional commandTimeOut As Integer = 30)
 
SQLConnection = New SqlConnection(connectionString)
SQLCommand = SQLConnection.CreateCommand()
SQLCommand.Connection.Open()
SQLCommand.CommandTimeout = commandTimeOut
End Sub
Public Sub AddParameter(ByVal paramName As String, ByVal paramValue As Object, Optional type As System.Data.SqlDbType = SqlDbType.VarChar)
 
Dim parameter As SqlParameter = SQLCommand.CreateParameter()
parameter.ParameterName = paramName
parameter.SqlDbType = type
parameter.Value = paramValue
SQLCommand.Parameters.Add(parameter)
End Sub
 
 
Public Function DataTable(ByVal strCommandText As String, typCommandType As CommandType) As DataTable
 
Dim DT As New DataTable
Dim ADPTR As SqlDataAdapter
With SQLCommand
.CommandText = strCommandText
.CommandType = typCommandType
End With
Do
Exception = Nothing
Try
ADPTR = New SqlDataAdapter(SQLCommand)
ADPTR.Fill(DT)
Return DT
Catch ex As Exception
Exception = ex
If ex.Message.ToLower.Contains("timeout") Then
Console.WriteLine(String.Format("SQL Timeout {0:hh:mm:ss}. Trying again...", Date.Now))
Else
Throw ex
End If
End Try
Loop
Return Nothing
End Function
Public Function ExecuteNonQuery(ByVal strCommandText As String, typCommandType As
CommandType) As Exception
 
Exception = Nothing
Try
With SQLCommand
.CommandText = strCommandText
.CommandType = typCommandType
If .Connection.State <> ConnectionState.Open Then .Connection.Open()
.ExecuteNonQuery()
End With
Catch ex As Exception
Exception = ex
End Try
Return Exception
End Function
 
End Class
 

Answers (2)