Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Connecting C#.Net to SQL Server 2000

Connecting C#.Net to SQL Server 2000

Scheduled Pinned Locked Moved C#
databasecsharpsql-serversysadmin
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    klaydze
    wrote on last edited by
    #1

    hi, i am a vb.net user and i want to try to convert my vb.net program to C#.Net. i have a class (clsDataAccess) where i execute my query. i'd try it to convert it to C#.Net but it gives me a lot of errors. i want to use this clsDataAccess as my default class when executing my query. can you pls help me to convert it. below is my code. Imports System Imports System.Data Imports System.Data.SqlClient Imports AddressBook.usermod1 Public Class clsDataAccess Public objConnection As SqlConnection Public objTransaction As SqlTransaction Public Function SqlConnect() As Boolean Try objConnection = New SqlConnection 'objConnection.ConnectionString = "Server=(local);database=AddressBook;user id=sa;password=;" objConnection.ConnectionString = "Server=" & GetServer("\conn.cfg") & "; DataBase=" & GetDatabase("\conn.cfg") & "; User ID =" & GetUser("\conn.cfg") & "; Integrated Security=false" If objConnection.State = ConnectionState.Closed Then _ objConnection.Open() Return True Catch ex As Exception MsgBox("Failed to connect to data source.", MsgBoxStyle.Information, "") Return False Finally objConnection.Close() End Try End Function Public Function ExecuteQuery(ByVal strSQL As String) As DataTable Dim objDataTable As DataTable Dim objDataAdapter As SqlDataAdapter Try SqlConnect() objDataAdapter = New SqlDataAdapter With objDataAdapter objDataTable = New DataTable .SelectCommand() = New SqlCommand(strSQL, objConnection, objTransaction) .Fill(objDataTable) Return objDataTable End With Catch sqlex As Exception Throw sqlex Catch ex As Runtime.InteropServices.COMException Throw ex Finally objDataAdapter = Nothing End Try End Function Public Sub ExecuteNonQuery(ByVal strSQL As String) Dim objSqlCommand As SqlCommand Try SqlConnect() objSqlCommand = New SqlCommand(strSQL, objConnection) objSqlCommand.Connection.Open() objSqlCommand.ExecuteNonQuery() Catch ex As SqlException Throw ex Catch ex As Runtime.InteropServices.COMException Throw ex Fina

    R A 2 Replies Last reply
    0
    • K klaydze

      hi, i am a vb.net user and i want to try to convert my vb.net program to C#.Net. i have a class (clsDataAccess) where i execute my query. i'd try it to convert it to C#.Net but it gives me a lot of errors. i want to use this clsDataAccess as my default class when executing my query. can you pls help me to convert it. below is my code. Imports System Imports System.Data Imports System.Data.SqlClient Imports AddressBook.usermod1 Public Class clsDataAccess Public objConnection As SqlConnection Public objTransaction As SqlTransaction Public Function SqlConnect() As Boolean Try objConnection = New SqlConnection 'objConnection.ConnectionString = "Server=(local);database=AddressBook;user id=sa;password=;" objConnection.ConnectionString = "Server=" & GetServer("\conn.cfg") & "; DataBase=" & GetDatabase("\conn.cfg") & "; User ID =" & GetUser("\conn.cfg") & "; Integrated Security=false" If objConnection.State = ConnectionState.Closed Then _ objConnection.Open() Return True Catch ex As Exception MsgBox("Failed to connect to data source.", MsgBoxStyle.Information, "") Return False Finally objConnection.Close() End Try End Function Public Function ExecuteQuery(ByVal strSQL As String) As DataTable Dim objDataTable As DataTable Dim objDataAdapter As SqlDataAdapter Try SqlConnect() objDataAdapter = New SqlDataAdapter With objDataAdapter objDataTable = New DataTable .SelectCommand() = New SqlCommand(strSQL, objConnection, objTransaction) .Fill(objDataTable) Return objDataTable End With Catch sqlex As Exception Throw sqlex Catch ex As Runtime.InteropServices.COMException Throw ex Finally objDataAdapter = Nothing End Try End Function Public Sub ExecuteNonQuery(ByVal strSQL As String) Dim objSqlCommand As SqlCommand Try SqlConnect() objSqlCommand = New SqlCommand(strSQL, objConnection) objSqlCommand.Connection.Open() objSqlCommand.ExecuteNonQuery() Catch ex As SqlException Throw ex Catch ex As Runtime.InteropServices.COMException Throw ex Fina

      R Offline
      R Offline
      Rocky
      wrote on last edited by
      #2

      looks like ur trying to convert a VB class to C# hope that link helps you Convert VB .NET to C#[^]

      Rocky Success is a ladder which you can't climb with your hands in your pockets.

      1 Reply Last reply
      0
      • K klaydze

        hi, i am a vb.net user and i want to try to convert my vb.net program to C#.Net. i have a class (clsDataAccess) where i execute my query. i'd try it to convert it to C#.Net but it gives me a lot of errors. i want to use this clsDataAccess as my default class when executing my query. can you pls help me to convert it. below is my code. Imports System Imports System.Data Imports System.Data.SqlClient Imports AddressBook.usermod1 Public Class clsDataAccess Public objConnection As SqlConnection Public objTransaction As SqlTransaction Public Function SqlConnect() As Boolean Try objConnection = New SqlConnection 'objConnection.ConnectionString = "Server=(local);database=AddressBook;user id=sa;password=;" objConnection.ConnectionString = "Server=" & GetServer("\conn.cfg") & "; DataBase=" & GetDatabase("\conn.cfg") & "; User ID =" & GetUser("\conn.cfg") & "; Integrated Security=false" If objConnection.State = ConnectionState.Closed Then _ objConnection.Open() Return True Catch ex As Exception MsgBox("Failed to connect to data source.", MsgBoxStyle.Information, "") Return False Finally objConnection.Close() End Try End Function Public Function ExecuteQuery(ByVal strSQL As String) As DataTable Dim objDataTable As DataTable Dim objDataAdapter As SqlDataAdapter Try SqlConnect() objDataAdapter = New SqlDataAdapter With objDataAdapter objDataTable = New DataTable .SelectCommand() = New SqlCommand(strSQL, objConnection, objTransaction) .Fill(objDataTable) Return objDataTable End With Catch sqlex As Exception Throw sqlex Catch ex As Runtime.InteropServices.COMException Throw ex Finally objDataAdapter = Nothing End Try End Function Public Sub ExecuteNonQuery(ByVal strSQL As String) Dim objSqlCommand As SqlCommand Try SqlConnect() objSqlCommand = New SqlCommand(strSQL, objConnection) objSqlCommand.Connection.Open() objSqlCommand.ExecuteNonQuery() Catch ex As SqlException Throw ex Catch ex As Runtime.InteropServices.COMException Throw ex Fina

        A Offline
        A Offline
        Ashfield
        wrote on last edited by
        #3

        This seems lazy to me. I would have thought it would be a good introduction to C#, converting existing code.

        Bob Ashfield Consultants Ltd

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups