Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
help me to create a class Conection in my project. i using database SQL Server 2005 and SQL server 2000. Please.!
Posted
Updated 19-Mar-12 5:29am
v2
Comments
Rajesh Anuhya 19-Mar-12 11:29am    
More details required.
--RA
OriginalGriff 19-Mar-12 11:30am    
Help us, to help you.
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, read your homework instructions, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Sergey Alexandrovich Kryukov 1-Aug-12 12:29pm    
Please, stop re-posting and posting non-questions in this forum. I already removed two of your posts.
--SA

1 solution

Start with
C#
public class Connection ...

What else do you need?
 
Share this answer
 
Comments
irwan sesab 1-Aug-12 10:02am    
I am sorry that poor english. I am an indonesian.
I've got the answer by my self, that is like this..


Imports Microsoft.VisualBasic
Imports System.Data.Sql
Imports System.Data.SqlClient

Public Class ClsKoneksi
Protected SQL As String
Protected Ds As DataSet
Protected TblPengguna As DataTable
Protected Cn As SqlConnection
Protected Cmd As SqlCommand
Protected Da As SqlDataAdapter

Public Function OpenConn() As Boolean
Cn = New SqlConnection("Data Source=localhost;Initial Catalog=dbPersediaan_Putusibau;Integrated Security=True")
Cn.Open()
If Cn.State <> ConnectionState.Open Then
Return False
Else
Return True
End If
End Function

Public Sub CloseConn()
If Not IsNothing(Cn) Then
Cn.Close()
Cn = Nothing
End If
End Sub

Public Function ExecuteQuery(ByVal Query As String) As DataTable
If Not OpenConn() Then
MsgBox("Koneksi Gagal.!", MsgBoxStyle.Critical, "Akses Gagal ExecuteQuery")
Return Nothing
Exit Function
End If
Cmd = New SqlCommand(Query, Cn)
Da = New SqlDataAdapter
Da.SelectCommand = Cmd
Ds = New DataSet
Da.Fill(Ds)
TblPengguna = Ds.Tables(0)
Return TblPengguna
TblPengguna = Nothing
Ds = Nothing
Da = Nothing
Cmd = Nothing
CloseConn()
End Function

Public Sub ExecuteNonQuery(ByVal Query As String)
If Not OpenConn() Then
MsgBox("Koneksi Gagal.!", MsgBoxStyle.Critical, "Akses Gagal NonQuery")
Exit Sub
End If
Cmd = New SqlCommand
Cmd.Connection = Cn
Cmd.CommandType = CommandType.Text
Cmd.CommandText = Query
Cmd.ExecuteNonQuery()
Cmd = Nothing
CloseConn()
End Sub
End Class

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900