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

Monday, June 28, 2004

Dot net Overloads Function Fill_Combo_Relation :

Public Overloads Function Fill_Combo_Relation :

This method is used to fill the given combo box with the data, from the specified table, which is based upon the selected Value of Master Combo box.
It accepts 4 arguments namely, DetailDataTable, masterCombo, ReleteFieldName and Detailcombo.
DetailDataTable – is the table where the data is to be retrieved.
MasterCombo – is the combo box from which the selected data is retrieved to match the rows from the DetailDataTable.
RelateFieldName – is the fieldname, which is used to set the filter condition.
Detailcombo – is the combo box that is to be filled with the selected data.
This method returns the data view object.



Public Overloads Function Fill_Combo_Relation(ByRef DetailDataTable As DataTable, ByRef MasterCombo As ComboBox, ByVal RelatefieldName As String, ByRef DetailCombo As ComboBox)
Try
Dim dv_view As New DataView(DetailDataTable)
dv_view.RowStateFilter = DataViewRowState.OriginalRows
dv_view.RowFilter = RelatefieldName & " = " & MasterCombo.SelectedValue.ToString
'MsgBox("Master ID : " & MasterCombo.SelectedValue.ToString)
If dv_view.Count > 0 Then
DetailCombo.DataSource = dv_view
DetailCombo.DisplayMember = dv_view.Table.Columns(1).ToString
DetailCombo.ValueMember = dv_view.Table.Columns(0).ToString
'DetailCombo.Focus()
Else
Dim dv As New DataView(tbl_Not_Available)
dv.RowFilter = "ID = '0'"
DetailCombo.DataSource = dv
DetailCombo.DisplayMember = dv.Table.Columns(1).ToString
DetailCombo.ValueMember = dv.Table.Columns(0).ToString
End If
Catch
End Try
End Function
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

Public Overloads Function Fill_Combo_Relation(ByRef DetailDataTable As DataTable, ByRef MasterCombo As ComboBox, ByVal RelatefieldName1 As String, ByVal RelatefieldName2 As String, ByVal Relatefieldvalue2 As Integer, ByRef DetailCombo As ComboBox)
Try
Dim dv_view As New DataView(DetailDataTable)
dv_view.RowStateFilter = DataViewRowState.OriginalRows
dv_view.RowFilter = RelatefieldName1 & " = " & MasterCombo.SelectedValue.ToString & " and " & RelatefieldName2 & " = " & Relatefieldvalue2
'MsgBox("Master ID : " & MasterCombo.SelectedValue.ToString)
If dv_view.Count > 0 Then
DetailCombo.DataSource = dv_view
DetailCombo.DisplayMember = dv_view.Table.Columns(1).ToString
DetailCombo.ValueMember = dv_view.Table.Columns(0).ToString
'DetailCombo.Focus()
Else
Dim dv As New DataView(tbl_Not_Available)
dv.RowFilter = "ID = '0'"
DetailCombo.DataSource = dv
DetailCombo.DisplayMember = dv.Table.Columns(1).ToString
DetailCombo.ValueMember = dv.Table.Columns(0).ToString
End If
Catch
End Try
End Function

Wednesday, June 23, 2004

Dot net Public Function Fill_Combo

Function Fill_Combo :

This method is used to fill the given Combobox with the data from the specified table.
It accepts 2 arguments, namely control and Dt
Control – object of the Combobox class.
Dt – object of the DataTable.
Following code snippet is the key lines.
control.DataSource = dt

control.DisplayMember = dt.Columns(1).ToString

control.ValueMember = dt.Columns(0).ToString

First line assigns ‘dt’ as the Datasource property for the Combobox.
Second line assign the string data to be displayed in the combobox as DsiplayMember property for the combobox.
Third line assign the data value to be gotten when the item is selected in the combobox. The property is ValueMember.

Public Function Fill_Combo(ByRef control As ComboBox, ByRef dt As DataTable)
Dim Not_Dt As DataTable
Try
If dt.Rows.Count > 0 Then
control.DataSource = dt
control.DisplayMember = dt.Columns(1).ToString
control.ValueMember = dt.Columns(0).ToString
Else
Not_Dt = tbl_Not_Available()
control.DataSource = Not_Dt
control.DisplayMember = Not_Dt.Columns(1).ToString
control.ValueMember = dt.Columns(0).ToString
'control.Items.Add("No Data Available")
End If
Catch
End Try
End Function

Saturday, June 19, 2004

Dot net : get_max_id

Function get_max_id :

This method is used to get the maximum id existing in the table.
It accepts 2 arguments, namely tbl_name and fld_name
Tbl_Name – Name of the Table.
Fld_Name – Name of the Id Field
It returns the Maximum Id as Integer.


Public Function get_max_id(ByVal tbl_name As String, ByVal fld_name As String) As Integer
Dim rd As Object
str_qry = "select max(" & fld_name & ") as Cnt from " & tbl_name
cmd = New SqlCommand(str_qry, con)
Try
con.Open()
rd = cmd.ExecuteScalar()
If rd.GetType Is GetType(DBNull) Then
result = 1
Else
result = CInt(rd) + 1
End If
Return result
Catch ex As Exception
MsgBox(ex.Message.ToString)
Finally
con.Close()
End Try
End Function

Thursday, June 17, 2004

DOt Net .. New()

New():
This is the constructor and it executes when an object is created for the class.
It establishes the connection with the back end database.


Sub New()
constr = "Data Source=10.94.5.3;User ID=sundar;Password=sun02dar;Initial Catalog=e_Payroll"
con = New SqlConnection(constr)
result = 0
End Sub

Saturday, June 12, 2004

Public Function GetColumnValue:

Public Function GetColumnValue:

This method is used to get the specified column value
It accepts 5 arguments namely, TableName, FieldName, KeyName, KeyValue and datatype
TableName – Name of the table
FieldName – Name of the Field
KeyName – Name of the Column Name used to filter the table.
Keyvalue – value used in the filter
Datatype – Datatype of the keyname.



Public Function GetColumnValue(ByVal TableName As String, ByVal FieldName As String, ByVal KeyName As String, ByVal KeyValue As String, ByVal datatype As String)
Dim result As String
Try
If datatype = "C" Then KeyValue = "'" & KeyValue & "'"
str_qry = "select " & FieldName & " as Colvalue from " & TableName & " WHERE " & KeyName & "=" & KeyValue
cmd = New SqlCommand(str_qry, con)
con.Open()
result = cmd.ExecuteScalar()
Return result
Catch ex As Exception
MsgBox(ex.Message.ToString)
Finally
con.Close()
End Try
End Function