I have written below code for my small winapp application - I am calling values to load defaults - it only appears when application gets loaded - on click button I am calling that method but it does not load default values
Can someone help me - what I am doing wrong ?
Public Class Form3
Dim afterhour_default As Integer = 0
Dim networkname As String
Dim dbaplatformid As Integer
Dim dbaname As String
Dim platformname As String
Dim dbaid As String
Dim SQLconnect As String = "Data Source=myserver;Initial Catalog=dms;Integrated Security=True"
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DBAWMSDataSet.Flag' table. You can move, or remove it, as needed.
Me.FlagTableAdapter.Fill(Me.DBAWMSDataSet.Flag)
'TODO: This line of code loads data into the 'DBAWMSDataSet.DBA' table. You can move, or remove it, as needed.
Me.DBATableAdapter.Fill(Me.DBAWMSDataSet.DBA)
'TODO: This line of code loads data into the 'DBAWMSDataSet.DBPlatForm' table. You can move, or remove it, as needed.
Me.DBPlatFormTableAdapter.Fill(Me.DBAWMSDataSet.DBPlatForm)
'TODO: This line of code loads data into the 'DBAWMSDataSet.Application' table. You can move, or remove it, as needed.
Me.ApplicationTableAdapter.Fill(Me.DBAWMSDataSet.Application)
'TODO: This line of code loads data into the 'DBAWMSDataSet.Category_WorkType' table. You can move, or remove it, as needed.
Me.Category_WorkTypeTableAdapter.Fill(Me.DBAWMSDataSet.Category_WorkType)
'TODO: This line of code loads data into the 'DBAWMSDataSet.WorkDetail' table. You can move, or remove it, as needed.
Me.WorkDetailTableAdapter.Fill(Me.DBAWMSDataSet.WorkDetail)
'TODO: This line of code loads data into the 'DBAWMSDataSet.WorkDetail' table. You can move, or remove it, as needed.
Me.WorkDetailTableAdapter.Fill(Me.DBAWMSDataSet.WorkDetail)
'Capture current user login and verify
networkname = System.Environment.UserDomainName + "\" + System.Environment.UserName
Dim connection As New SqlClient.SqlConnection
Dim command As New SqlClient.SqlCommand
Dim adaptor As New SqlClient.SqlDataAdapter
Dim dataset As New DataSet
connection.ConnectionString = (SQLconnect)
command.CommandText = "Select a.*, b.DBPLatform_DESc from DBA a join DBPlatForm b on a.DBPlID = b.DBPLID where a.DomainID = '" & networkname & "'"
connection.Open()
command.Connection = connection
adaptor.SelectCommand = command
adaptor.Fill(dataset, "0")
Dim count = dataset.Tables(0).Rows.Count
If count < 1 Then
MsgBox("Please contact System Adminstrator for Login", MsgBoxStyle.Critical, "WMS")
Close()
Else
dbaid = dataset.Tables(0).Rows(0).Item(0)
dbaplatformid = dataset.Tables(0).Rows(0).Item(3)
dbaname = dataset.Tables(0).Rows(0).Item(2)
platformname = dataset.Tables(0).Rows(0).Item(4)
Me.Text = "Work Load Management System Logged in User : " & dbaname
connection.Close()
Load_Defaults()
End If
End Sub
Private Sub Load_Defaults()
'Default Values for the fields
afterhours_box.SelectedIndex = afterhour_default
Me.WorkDateDateTimePicker.Text = Date.Today()
Me.ComboBox_DBA.Text = dbaname
Me.ComboBox_Platform.Text = platformname
End Sub
Private Sub WorkDetailBindingNavigatorSaveItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WorkDetailBindingNavigatorSaveItem.Click
Me.Validate()
Me.WorkDetailBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.DBAWMSDataSet)
End Sub
Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click
Me.Validate()
Me.WorkDetailBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.DBAWMSDataSet)
Call Load_Defaults()
End Sub
End Class
Can someone help me - what I am doing wrong ?
Public Class Form3
Dim afterhour_default As Integer = 0
Dim networkname As String
Dim dbaplatformid As Integer
Dim dbaname As String
Dim platformname As String
Dim dbaid As String
Dim SQLconnect As String = "Data Source=myserver;Initial Catalog=dms;Integrated Security=True"
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DBAWMSDataSet.Flag' table. You can move, or remove it, as needed.
Me.FlagTableAdapter.Fill(Me.DBAWMSDataSet.Flag)
'TODO: This line of code loads data into the 'DBAWMSDataSet.DBA' table. You can move, or remove it, as needed.
Me.DBATableAdapter.Fill(Me.DBAWMSDataSet.DBA)
'TODO: This line of code loads data into the 'DBAWMSDataSet.DBPlatForm' table. You can move, or remove it, as needed.
Me.DBPlatFormTableAdapter.Fill(Me.DBAWMSDataSet.DBPlatForm)
'TODO: This line of code loads data into the 'DBAWMSDataSet.Application' table. You can move, or remove it, as needed.
Me.ApplicationTableAdapter.Fill(Me.DBAWMSDataSet.Application)
'TODO: This line of code loads data into the 'DBAWMSDataSet.Category_WorkType' table. You can move, or remove it, as needed.
Me.Category_WorkTypeTableAdapter.Fill(Me.DBAWMSDataSet.Category_WorkType)
'TODO: This line of code loads data into the 'DBAWMSDataSet.WorkDetail' table. You can move, or remove it, as needed.
Me.WorkDetailTableAdapter.Fill(Me.DBAWMSDataSet.WorkDetail)
'TODO: This line of code loads data into the 'DBAWMSDataSet.WorkDetail' table. You can move, or remove it, as needed.
Me.WorkDetailTableAdapter.Fill(Me.DBAWMSDataSet.WorkDetail)
'Capture current user login and verify
networkname = System.Environment.UserDomainName + "\" + System.Environment.UserName
Dim connection As New SqlClient.SqlConnection
Dim command As New SqlClient.SqlCommand
Dim adaptor As New SqlClient.SqlDataAdapter
Dim dataset As New DataSet
connection.ConnectionString = (SQLconnect)
command.CommandText = "Select a.*, b.DBPLatform_DESc from DBA a join DBPlatForm b on a.DBPlID = b.DBPLID where a.DomainID = '" & networkname & "'"
connection.Open()
command.Connection = connection
adaptor.SelectCommand = command
adaptor.Fill(dataset, "0")
Dim count = dataset.Tables(0).Rows.Count
If count < 1 Then
MsgBox("Please contact System Adminstrator for Login", MsgBoxStyle.Critical, "WMS")
Close()
Else
dbaid = dataset.Tables(0).Rows(0).Item(0)
dbaplatformid = dataset.Tables(0).Rows(0).Item(3)
dbaname = dataset.Tables(0).Rows(0).Item(2)
platformname = dataset.Tables(0).Rows(0).Item(4)
Me.Text = "Work Load Management System Logged in User : " & dbaname
connection.Close()
Load_Defaults()
End If
End Sub
Private Sub Load_Defaults()
'Default Values for the fields
afterhours_box.SelectedIndex = afterhour_default
Me.WorkDateDateTimePicker.Text = Date.Today()
Me.ComboBox_DBA.Text = dbaname
Me.ComboBox_Platform.Text = platformname
End Sub
Private Sub WorkDetailBindingNavigatorSaveItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WorkDetailBindingNavigatorSaveItem.Click
Me.Validate()
Me.WorkDetailBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.DBAWMSDataSet)
End Sub
Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click
Me.Validate()
Me.WorkDetailBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.DBAWMSDataSet)
Call Load_Defaults()
End Sub
End Class