Internet is growing Every Seconds :: Industry is growing Every Year

Sunday, July 18, 2004

Public Function Add_Rec :

Public Function Add_Rec :

This method is used to insert a row in the table
It accepts one argument namely sqlstr
ExecuteNonQuery method of command object executes the given query and returns number of records.


Public Function Add_Rec(ByVal sqlstr As String)
Try
'MsgBox(sqlstr)
cmd = New SqlCommand(sqlstr, con)
con.Open()
result = cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.ToString)
Finally
con.Close()
End Try
End Function

Thursday, July 15, 2004

Public Function Get_Rec :

Public Function Get_Rec :

This method is used to get number of records from the specified table.
It accepts one argument namely sqlstr.
Da is the object of sqlDataAdapter class
Ds is the object of Dataset class
Dt is the object of DataTable.
Fill method of sqlDataadapter class get the records from specified database and stores in the dataset object
This method returns datatable object


Public Function Get_Rec(ByVal sqlstr As String) As DataTable
Dim da As New SqlDataAdapter(sqlstr, con)
Dim ds As New DataSet
Dim dt As DataTable
Try
'MsgBox(sqlstr)
da.Fill(ds)
dt = ds.Tables(0)
da = Nothing
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Return dt
End Function

Monday, July 12, 2004

Public Function execute_qry :

Public Function execute_qry :

This method is used to execute the ‘sql’ query.
It accepts one argument namely str_qry.
Cmd is the object of the sqlcommand class
Con is the object of the sqlconnection class
Executescalar method of command object executes the given query and returns the first column value of the first row.


Public Function execute_qry(ByVal str_qry As String)
result = 0
Try
cmd = New SqlCommand(str_qry, con)
con.Open()
result = cmd.ExecuteScalar
Catch ex As Exception
MsgBox(ex.ToString)
Finally
con.Close()
End Try
End Function

Tuesday, July 06, 2004

Public Overloads Function IsRecordExist

Public Overloads Function IsRecordExist :

This method is used to find the specified Record Exists in the table.
This accepts 4 arguments namely, TableName, FieldName, FieldValue and Datatype.
TableName – Name of the table
FieldName – Name of the Field
Fieldvalue – value of the field
Datatype – Datatype of the Fieldname.



Public Overloads Function IsRecordExist(ByVal TableName As String, ByVal fieldname As String, ByVal fieldvalue As String, ByVal datatype As String) As Boolean
'str_qry = "select " & fieldname & " from " & TableName & " where "
str_qry = "select count(*) from " & TableName & " where "
If UCase(datatype) = "C" Then
fieldvalue = "'" & fieldvalue & "'"
End If
str_qry = str_qry & fieldname & " =" & fieldvalue & ""
'MsgBox(str_qry)
execute_qry(str_qry)
If result > 0 Then
Return True
Else
Return False
End If
End Function


//////////////////////////////////////////////////////////////////////////////////////////////////

Public Overloads Function IsRecordExist(ByVal TableName As String, ByVal fieldname1 As String, ByVal fieldvalue1 As String, ByVal datatype1 As String, ByVal fieldname2 As String, ByVal fieldvalue2 As String, ByVal datatype2 As String) As Boolean
If UCase(datatype1) = "C" Then
fieldvalue1 = "'" & fieldvalue1 & "'"
End If
If UCase(datatype2) = "C" Then
fieldvalue2 = "'" & fieldvalue2 & "'"
End If
str_qry = "select count(*) from " & TableName & " where "
str_qry = str_qry & fieldname1 & " =" & fieldvalue1 & " and "
str_qry = str_qry & fieldname2 & " =" & fieldvalue2 & ""

execute_qry(str_qry)
If result > 0 Then
Return True
Else
Return False
End If
End Function

//////////////////////////////////////////////////////////////////////////////////////////////////
Public Overloads Function IsRecordExist(ByVal TableName As String, ByVal fieldname1 As String, ByVal fieldvalue1 As String, ByVal datatype1 As String, ByVal fieldname2 As String, ByVal fieldvalue2 As String, ByVal datatype2 As String, ByVal fieldname3 As String, ByVal fieldvalue3 As String, ByVal datatype3 As String) As Boolean
If UCase(datatype1) = "C" Then fieldvalue1 = "'" & fieldvalue1 & "'"
If UCase(datatype2) = "C" Then fieldvalue2 = "'" & fieldvalue2 & "'"
If UCase(datatype3) = "C" Then fieldvalue3 = "'" & fieldvalue3 & "'"

str_qry = "select count(*) from " & TableName & " where "
str_qry = str_qry & fieldname1 & " =" & fieldvalue1 & " and "
str_qry = str_qry & fieldname2 & " =" & fieldvalue2 & " and "
str_qry = str_qry & fieldname3 & " =" & fieldvalue3
'MsgBox(str_qry)
execute_qry(str_qry)
If result > 0 Then
Return True
Else
Return False
End If
End Function
//////////////////////////////////////////////////////////////////////////////////////////////////