proberto 0 Denunciar post Postado Setembro 28, 2008 :unsure: Caros amigos; Tenho essa classe "CLsConexaoSQL feita no Vb.net. Imports System.Data.SqlClient 'Importando o Namespace do SQLclasse ------------------------------------------------------------------ Public MustInherit Class ClsConexaoSQL 'Objeto que não pode ser Instanciado diretamente "Classe Selada" tem que ser herdada Private Conexao As New SqlConnection 'Criando um metodo de Conexao Private PDataSource As String Private PInitial As String Private Puserid As String Private PPassword As String Private PIntegrado As Boolean = True ------------------------------------------------------------------- Public Property _DBConAtiva() As SqlConnection '__DBConAtiva e uma Propriedade Get 'Resgatando um valor da conexão Return Conexao End Get Set(ByVal Value As SqlConnection) 'Atribuindo um valor Conexao = Value End Set End Property ------------------------------------------------------------------- Public Property _DataSource() As String Get Return PDataSource End Get Set(ByVal Value As String) ' o Valor foi determinado no inicio com String PDataSource = Value End Set End Property ------------------------------------------------------------------- Public Property _Initial() As String Get Return PInitial End Get Set(ByVal Value As String) ' o Valor foi determinado no inicio com String PInitial = Value End Set End Property ------------------------------------------------------------------- Public Property _UserID() As String Get Return Puserid End Get Set(ByVal Value As String) ' o Valor foi determinado no inicio com String Puserid = Value End Set End Property ------------------------------------------------------------------- Public Property _Password() As String Get Return PPassword End Get Set(ByVal Value As String) ' o Valor foi determinado no inicio com String PPassword = Value End Set End Property ------------------------------------------------------------------- Public Property _Integrado() As Boolean Get Return PIntegrado End Get Set(ByVal Value As Boolean) ' o Valor foi determinado no inicio com String PIntegrado = Value End Set End Property ------------------------------------------------------------------- Public Function IniciaConexao() 'Vai pegar da propriedade 'Dim StrConexao As String Dim Conexaolocal As New SqlConnection Try 'Codigo que pode ocorrer o erro 'StrConexao = "" Conexaolocal.ConnectionString = StrConecta 'Conexaolocal recebe o valor de StrConecta 'Que Abre a Conexão Conexaolocal.Open() 'Verificando se o status da conexao esta aberta If Conexaolocal.State = ConnectionState.Open Then Me._DBConAtiva = Conexaolocal End If Catch SQLerro As SqlException 'Tratamento do erro Throw New Exception(SQLerro.Message) 'Throw devolve o erro ao aplicativo chamador Catch ex As Exception Throw New Exception(ex.Message) Finally 'Tudo que estiver entre o Finally e o End try sera executado GC.Collect() 'Garbage Collection(GC)Força a execução do coletor de lixo End Try End Function ------------------------------------------------------------------- Public ReadOnly Property StrConecta() As String Get 'If PDataSource.Trim.Length > 0 Then If Not IsNothing(PDataSource) Then 'se a conexao existir Dim StrCom As New System.Text.StringBuilder With StrCom .Append("DATA SOURCE = ") 'Estou agregando(Append)um valor da string .Append(_DataSource) .Append(";") .Append("initial catalog =") .Append(_Initial + ";") .Append("User Id = ") .Append(_UserID) .Append(";") .Append("Password =") .Append(_Password) .Append(";") End With StrConecta = StrCom.ToString Else 'String de Conexao, a outra esta no modulo ModIncluir StrConecta = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DBCei;Data Source=CASA-01\SQLEXPRESS" '"Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=DBCei;Data Source=casa-01" End If Return StrConecta End Get End Property End Class-------------------------------------------------------------------Alguem pode me ajudar a passar ela para C# Muito Obrigado. Compartilhar este post Link para o post Compartilhar em outros sites
quintelab 91 Denunciar post Postado Setembro 29, 2008 De uma olhada neste site e veja se te ajuda: http://www.carlosag.net/Tools/CodeTranslator/ Existem outros parecidos na web. Abraços... Compartilhar este post Link para o post Compartilhar em outros sites
jpaulino 2 Denunciar post Postado Outubro 7, 2008 Este conversor é muito bom: http://www.developerfusion.com/tools/convert/csharp-to-vb/ Compartilhar este post Link para o post Compartilhar em outros sites