hi all , i now working on new project that have a class for table includes the add , delete , and update function
how i can call them in vb???
this one of the class
Imports System.Data
Imports System.Data.SqlClient
Public Class BOQSectionsAndParts
Private _BOQSectionsAndParts_ID as Integer = 0
Private _ProjectTenderingNO as String = ""
Private _BOQSection as String = ""
Private _Part as String = ""
Public Property BOQSectionsAndParts_ID() As Integer
Get
Return Me._BOQSectionsAndParts_ID
End Get
Set(ByVal value As Integer)
Me._BOQSectionsAndParts_ID= value
End Set
End Property
Public Property ProjectTenderingNO() As String
Get
Return Me._ProjectTenderingNO
End Get
Set(ByVal value As String)
Me._ProjectTenderingNO= value
End Set
End Property
Public Property BOQSection() As String
Get
Return Me._BOQSection
End Get
Set(ByVal value As String)
Me._BOQSection= value
End Set
End Property
Public Property Part() As String
Get
Return Me._Part
End Get
Set(ByVal value As String)
Me._Part= value
End Set
End Property
Private conn As Sqlconnection
Private _Msg As String = ""
Public ReadOnly Property Msg() As String
Get
Return Me._Msg
End Get
End Property
Private Sub Getconnection()
Try
Dim DbConnection As String = System.Configuration.ConfigurationManager.ConnectionStrings("Tendering_System").ConnectionString
Me.conn = New SqlConnection(DbConnection)
Me.conn.Open()
Catch ex As Exception
Me._Msg = "We can not establish a connection to the database"
End Try
End Sub
Public Sub add()
Getconnection()
Dim sql As String = "INSERT INTO BOQSectionsAndParts (ProjectTenderingNO, BOQSection, Part) VALUES(@ProjectTenderingNO, @BOQSection, @Part)"
Dim Cmd As New SqlCommand(sql, Me.conn)
Cmd.Parameters.Add("@ProjectTenderingNO", SqlDbType.nvarchar).Value = _ProjectTenderingNO
Cmd.Parameters.Add("@BOQSection", SqlDbType.nvarchar).Value = _BOQSection
Cmd.Parameters.Add("@Part", SqlDbType.nvarchar).Value = _Part
Try
Cmd.ExecuteNonQuery()
Catch ex As SQLException
Me._Msg="Error Message"
Finally
Try
Me.conn.Close()
Catch
End Try
End Try
End Sub
Public Sub update()
Getconnection()
Dim sql As String = "UPDATE BOQSectionsAndParts Set ProjectTenderingNO= @ProjectTenderingNO, BOQSection= @BOQSection, Part= @Part Where BOQSectionsAndParts_ID = @BOQSectionsAndParts_ID"
Dim Cmd As New SqlCommand(sql, Me.conn)
Cmd.Parameters.Add("@BOQSectionsAndParts_ID", SqlDbType.int).Value = _BOQSectionsAndParts_ID
Cmd.Parameters.Add("@ProjectTenderingNO", SqlDbType.nvarchar).Value = _ProjectTenderingNO
Cmd.Parameters.Add("@BOQSection", SqlDbType.nvarchar).Value = _BOQSection
Cmd.Parameters.Add("@Part", SqlDbType.nvarchar).Value = _Part
Try
Cmd.ExecuteNonQuery()
Catch ex As SQLException
Me._Msg="Error Message"
Finally
Try
Me.conn.Close()
Catch
End Try
End Try
End Sub
Public Sub delete()
Getconnection()
Dim sql As String = "DELETE from BOQSectionsAndParts Where BOQSectionsAndParts_ID= @BOQSectionsAndParts_ID"
Dim Cmd As New SqlCommand(sql, Me.conn)
Cmd.Parameters.Add("@BOQSectionsAndParts_ID", SqlDbType.int).Value = _BOQSectionsAndParts_ID
Try
Cmd.ExecuteNonQuery()
Catch ex As SQLException
Me._Msg="Error Message"
Finally
Try
Me.conn.Close()
Catch
End Try
End Try
End Sub
End Class
, what i can write inside add , delete, update button related with datagridview
Imports System.Data
Imports System.Data.SqlClient
Public Class BOQSectionsAndParts
Private _BOQSectionsAndParts_ID as Integer = 0
Private _ProjectTenderingNO as String = ""
Private _BOQSection as String = ""
Private _Part as String = ""
Public Property BOQSectionsAndParts_ID() As Integer
Get
Return Me._BOQSectionsAndParts_ID
End Get
Set(ByVal value As Integer)
Me._BOQSectionsAndParts_ID= value
End Set
End Property
Public Property ProjectTenderingNO() As String
Get
Return Me._ProjectTenderingNO
End Get
Set(ByVal value As String)
Me._ProjectTenderingNO= value
End Set
End Property
Public Property BOQSection() As String
Get
Return Me._BOQSection
End Get
Set(ByVal value As String)
Me._BOQSection= value
End Set
End Property
Public Property Part() As String
Get
Return Me._Part
End Get
Set(ByVal value As String)
Me._Part= value
End Set
End Property
Private conn As Sqlconnection
Private _Msg As String = ""
Public ReadOnly Property Msg() As String
Get
Return Me._Msg
End Get
End Property
Private Sub Getconnection()
Try
Dim DbConnection As String = System.Configuration.ConfigurationManager.ConnectionStrings("Tendering_System").ConnectionString
Me.conn = New SqlConnection(DbConnection)
Me.conn.Open()
Catch ex As Exception
Me._Msg = "We can not establish a connection to the database"
End Try
End Sub
Public Sub add()
Getconnection()
Dim sql As String = "INSERT INTO BOQSectionsAndParts (ProjectTenderingNO, BOQSection, Part) VALUES(@ProjectTenderingNO, @BOQSection, @Part)"
Dim Cmd As New SqlCommand(sql, Me.conn)
Cmd.Parameters.Add("@ProjectTenderingNO", SqlDbType.nvarchar).Value = _ProjectTenderingNO
Cmd.Parameters.Add("@BOQSection", SqlDbType.nvarchar).Value = _BOQSection
Cmd.Parameters.Add("@Part", SqlDbType.nvarchar).Value = _Part
Try
Cmd.ExecuteNonQuery()
Catch ex As SQLException
Me._Msg="Error Message"
Finally
Try
Me.conn.Close()
Catch
End Try
End Try
End Sub
Public Sub update()
Getconnection()
Dim sql As String = "UPDATE BOQSectionsAndParts Set ProjectTenderingNO= @ProjectTenderingNO, BOQSection= @BOQSection, Part= @Part Where BOQSectionsAndParts_ID = @BOQSectionsAndParts_ID"
Dim Cmd As New SqlCommand(sql, Me.conn)
Cmd.Parameters.Add("@BOQSectionsAndParts_ID", SqlDbType.int).Value = _BOQSectionsAndParts_ID
Cmd.Parameters.Add("@ProjectTenderingNO", SqlDbType.nvarchar).Value = _ProjectTenderingNO
Cmd.Parameters.Add("@BOQSection", SqlDbType.nvarchar).Value = _BOQSection
Cmd.Parameters.Add("@Part", SqlDbType.nvarchar).Value = _Part
Try
Cmd.ExecuteNonQuery()
Catch ex As SQLException
Me._Msg="Error Message"
Finally
Try
Me.conn.Close()
Catch
End Try
End Try
End Sub
Public Sub delete()
Getconnection()
Dim sql As String = "DELETE from BOQSectionsAndParts Where BOQSectionsAndParts_ID= @BOQSectionsAndParts_ID"
Dim Cmd As New SqlCommand(sql, Me.conn)
Cmd.Parameters.Add("@BOQSectionsAndParts_ID", SqlDbType.int).Value = _BOQSectionsAndParts_ID
Try
Cmd.ExecuteNonQuery()
Catch ex As SQLException
Me._Msg="Error Message"
Finally
Try
Me.conn.Close()
Catch
End Try
End Try
End Sub
HibaPro -3 Junior Poster
Maligui 1 Application Developer
HibaPro -3 Junior Poster
Reverend Jim 4,968 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.