Close form from second form - vb.net

My first form is login form, when user correctly log in i am hiding login form and showing up second form. Now instead of hiding login form i want to close it from second form. I thought i will be able to do it but somehow i got troubles with it.
So far i did like this below.
I made interface which my FrmLogin implements:
Public Class FrmLogin
Implements ICloseLogin
Interface:
Public Interface ICloseLogin
Sub Close()
End Interface
FrmLogin implementing interface:
Private Sub ICloseLogin_Close() Implements ICloseLogin.Close
Me.Close()
End Sub
Now i am passing FrmLogin (Me) to second form constructor:
Private Sub ShowMainForm()
Dim FrmMain As New FrmMainMDI(Me)
FrmMain.IsMdiContainer = True
FrmMain.StartPosition = FormStartPosition.CenterScreen
FrmMain.Show()
'Me.Hide() 'not anymore
End Sub
Second form:
Public Class FrmMainMDI
Private closeloginfform As ICloseLogin
Sub New(frmlogin As ICloseLogin)
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
closeloginfform = frmlogin
End Sub
Private Sub FrmMainMDI_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
closeloginfform.Close()
End Sub
and when i debug and when it comes to line: closeloginfform.Close() i suppose to see only FrmLogin to be closed, but all is closing somehow. Why?
For further discussion:
Imports DataAccessLayer
Imports FormsUtils
Imports BusinessLayer
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Reflection
Imports System.IO
Imports Microsoft.WindowsAPICodePack.Dialogs
Imports Probix
Public Class FrmLogin
Private Property Form As New FormUtils
Private Property DB As New Procs
Private Property _login As String
Private Property _password As String
Private Sub btnLogin_Click(sender As System.Object, e As System.EventArgs) Handles btnLogin.Click
CheckAccess()
End Sub
Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
Private Sub FrmLogin_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
DB.OpenConn()
If DB.conn.State = ConnectionState.Open Then
Call Form.InitCombo(CboLogin, "SELECT * from tbLogin", DB.conn, "Login", "Login")
Call Form.InitCombo(CboLanguage, "SELECT * from tbLanguage where Active = 1", DB.conn, "Language", "Id")
Lang.name = DirectCast([Enum].Parse(GetType(Lang.LangShortcut), CboLanguage.GetItemText(CboLanguage.SelectedItem)), Lang.LangShortcut)
Else
Logger.LogIt(Modules.FrmLogin.ToString & ": " & Methods.FrmLogin_Load.ToString, WriteMsg.Write(IssueCode.SqlServerConnectionError_pl), Application.StartupPath & "\log.txt", False)
Application.Exit()
End If
Catch ex As Exception
Logger.LogIt(ex.tostring)
Application.Exit()
Finally
DB.CloseConn()
End Try
End Sub
Private Sub CheckAccess()
Try
_login = CboLogin.SelectedValue
_password = txtPassword.Text
If Not String.IsNullOrEmpty(txtPassword.Text) And Form.WybranoCombo(CboLogin, "Zaznacz login") Then
Dim strcon = New AppSettingsReader().GetValue("ConnectionString", GetType(System.String)).ToString()
Using con As New SqlConnection(strcon)
Using cmd As New SqlCommand("Select COUNT(*) FROM tbLogin WHERE Login = #Login And Password = #Password", con)
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("#Login", _login)
cmd.Parameters.AddWithValue("#Password", _password)
con.Open()
Dim o As Integer = cmd.ExecuteScalar()
'--CREDENTIALS OK
If o > 0 Then
CboLogin.Hide()
txtPassword.Hide()
btnLogin.Hide()
Label1.Hide()
Label2.Hide()
Try
Catch ex As Exception
MsgBox(ex.ToString)
End
End Try
'--CREDENTIALS NOT OK !!
Else
MsgBox("Wrong credentials")
End If
End Using
End Using
Else
MsgBox("Write some password !!")
End If
Catch ex As Exception
Logger.LogIt(Modules.FrmLogin.ToString & ":" & Methods.FrmLogin_Load.ToString, WriteMsg.Write(IssueCode.Unknown_pl) & " ------> EX-MESSAGE: " & ex.ToString, Application.StartupPath & " \log.txt", False)
Return
End Try
End Sub
Public Sub taskDialog_Opened(sender As Object, e As EventArgs)
Dim taskDialog As TaskDialog = TryCast(sender, TaskDialog)
taskDialog.Icon = taskDialog.Icon
If Not taskDialog.FooterIcon = TaskDialogStandardIcon.None Then
taskDialog.FooterIcon = taskDialog.FooterIcon
End If
taskDialog.InstructionText = taskDialog.InstructionText
End Sub
End Class
Module Program:
Module Program
Public Sub main()
Application.EnableVisualStyles()
Dim result As DialogResult
Using frmL As New FrmLogin
result = frmL.ShowDialog
End Using
If result = DialogResult.OK Then
Dim FrmMainMDI As New FrmMainMDI()
Application.Run(FrmMain)
End If
End Sub
End Module
Further discussion 2
Solved???: I've added line within CheckAccess() sub, this line:
Me.DialogResult = DialogResult.OK
so this peace of code has been changed only:
...
'--CREDENTIALS OK
If o > 0 Then
CboLogin.Hide()
txtPassword.Hide()
btnLogin.Hide()
Label1.Hide()
Label2.Hide()
Try
'*************************************
Me.DialogResult = DialogResult.OK '<=========================================
'*************************************
Catch ex As Exception
MsgBox(ex.ToString)
End
End Try
'--CREDENTIALS NOT OK !!
Else
MsgBox("Wrong credentials")
End If
...

A less involved way to do this is to start your app from Sub Main and only start the app if the LogIn is correct. For this:
Add a module to your App, and name it Program. Add a Public Sub Main to it
Go to Project Properties and Uncheck Enable Application Framework
Now, for the Startup Object, select "Sub Main"
You can actually name the module anything, "Program" is descriptive and the convention used in C#. Then the Sub Main code:
Public Sub Main()
Application.EnableVisualStyles()
Dim result As DialogResult
Using frmL As New frmLogin
result = frmL.ShowDialog
End Using
If result = DialogResult.OK Then
frmMain = New MainFrm()
Application.Run(frmMain)
End If
End Sub
Now, your two forms don't even have to know about each other. The MainForm will not even exist if/when the login fails. Whatever overhead there is related to starting/Loading the MainForm is also delayed until (and unless) the log in passes.
Your login button would be something like this (depending on how many failed attempts are allowed):
Private Sub btnLogIn_Click(sender As Object, e As EventArgs) Handles btnLogIn.Click
If IsValidUser(tbName.Text, tbPW.Text) Then
DialogResult = Windows.Forms.DialogResult.OK
Else
If tries >= 3 Then
DialogResult = Windows.Forms.DialogResult.Cancel
Else
tries += 1
Exit Sub
End If
End If
Me.Hide()
End Sub

Related

Filtering a data grid view using a combo box

When I select an element from the combo box, the DGV clears.
There is an Access database that has a table with room booking details, the code is supposed to use the combo box to filter the data to only show the selected room type.
I'm not sure if this code is on the right lines, so any help is appreciated.
Code for the form:
Imports System.Data.OleDb
Public Class frmViewEditBookings
Private DB As New DBControl
Private CurrentRecord As Integer = 0
'Error checking and reporting
Private Function NoErrors(Optional Report As Boolean = False) As Boolean
If Not String.IsNullOrEmpty(DB.Exception) Then
If Report = True Then MsgBox(DB.Exception)
Return False
Else
Return True
End If
End Function
Private Function NotEmpty(text As String) As Boolean
Return Not String.IsNullOrEmpty(text)
End Function
Public Sub RefreshGrid()
'Run query
DB.ExecQuery("SELECT * FROM tblRoomBookings")
'Report and abort on errors
If NoErrors(True) = False Then Exit Sub
'Fill combo box
For Each R As DataRow In DB.DT.Rows
cboRoomType.Items.Add(R("RoomType"))
Next
'If data is returned populate DGV and build update command
If DB.RecordCount > 0 Then
dgvBookings.DataSource = DB.DS.Tables(0)
dgvBookings.Rows(0).Selected = True
End If
End Sub
Private Sub frmViewEditBookings_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
'Perform subroutine RefreshGrid
RefreshGrid()
'Display specified room
If DB.RecordCount > 0 Then cboRoomType.SelectedIndex = 0
'Disable Save Button
btnSave.Enabled = False
End Sub
Private Sub SearchRoomType(RoomType As String)
'Add parameters and run query
DB.AddParam("#RoomType", RoomType)
DB.ExecQuery("SELECT * FROM tblRoomBookings WHERE RoomType =#RoomType")
'Report and abort on errors
If NotEmpty(DB.Exception) Then MsgBox(DB.Exception) : Exit Sub
'Report and abort on errors
If NoErrors(True) = False OrElse DB.RecordCount < 1 Then Exit Sub
End Sub
Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
'Run subroutine SearchRoomType
SearchRoomType(cboRoomType.Text)
End Sub
Private Sub cboRoomType_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboRoomType.SelectedIndexChanged
If Not String.IsNullOrEmpty(cboRoomType.Text) Then SearchRoomType(cboRoomType.Text)
'Hide lblSearch
lblSearchRoomType.Visible = False
End Sub
Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
'Close the form
Me.Close()
End Sub
End Class
DBControl class:
Imports System.Data.OleDb
Public Class DBControl
'Create connection to the database
Private DBCon As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" &
"Data Source=|DataDirectory|\NewHotel.mdb;")
'Prepare the database command
Private DBCmd As OleDbCommand
'Database data
Public DBDA As OleDbDataAdapter
Public DT As DataTable
Public DS As DataSet
'Query parameters
Public Params As New List(Of OleDbParameter)
'Query stats
Public RecordCount As Integer
Public Exception As String
Public Sub ExecQuery(Query As String)
'Reset query stats
RecordCount = 0
Exception = ""
Try
'Open database connection
DBCon.Open()
'Create database command
DBCmd = New OleDbCommand(Query, DBCon)
'Load params into database command
Params.ForEach(Sub(x) DBCmd.Parameters.Add(x))
'Clear params list
Params.Clear()
'Execute command and fill database
DS = New DataSet
DT = New DataTable
DBDA = New OleDbDataAdapter(DBCmd)
RecordCount = DBDA.Fill(DS)
DBCon.Close()
Catch ex As Exception
Exception = ex.Message
End Try
'Close connection to database
If DBCon.State = ConnectionState.Open Then DBCon.Close()
End Sub
'Include query and command parameters
Public Sub AddParam(Name As String, Value As Object)
Dim NewParam As New OleDbParameter(Name, Value)
Params.Add(NewParam)
End Sub
End Class
Thank you for your time :)

How to refresh data while saving in vb.net?

I want to refresh my data while clicking save button. I am using a datagridview but it won't refresh automatically. How can I code it?
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim sql As String = "INSERT INTO tblproduct (product, Supplierprice, Projectprice) VALUES (#product, #Supplierprice, #Projectprice)"
cmd = New MySqlCommand(sql, con)
'parameters()
cmd.Parameters.AddWithValue("#product", txtproductname.Text)
cmd.Parameters.AddWithValue("#Supplierprice", txtsupprice.Text)
cmd.Parameters.AddWithValue("#Projectprice", txtproprice.Text)
Try
con.Open()
If MessageBox.Show("Are You Sure To Save This?", "SAVE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
If cmd.ExecuteNonQuery() > 0 Then
MsgBox("Successfully Saved")
End If
End If
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
con.Close()
End Try
Refresh()
Hide()
End Sub
This is the way I would do it.
First create a class.
Public Class Product
Public Sub New(productName As String, supplierPrice As String, projectPrice As String)
Me.ProductName = productName
Me.SupplierPrice = supplierPrice
Me.ProjectPrice = projectPrice
End Sub
Public Property ProductName As String
Public Property SupplierPrice As String
Public Property ProjectPrice As String
End Class
Declare a BindingList of the class and use that as the datasource. When adding an item, just add to the BindingList. The grid will automatically be refreshed.
Public Class Form1
Private Products As New BindingList(Of Product)
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
dgvProducts.DataSource = Products
End Sub
Private Sub bnAdd_Click(sender As Object, e As EventArgs) Handles bnAdd.Click
Dim item As Product = New Product(tbProductName.Text, tbSupplierPrice.Text, tbProjectPrice.Text)
If MessageBox.Show($"Are You Sure To Save the product : {item.ProductName}?", "SAVE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
SaveProduct(item)
Products.Add(item)
End If
End Sub
Private Sub SaveProduct(item As Product)
'Add database insert code
End Sub
End Class

VB LAN Messenger having issues

I have made a small LAN messenger and I tried it with two pc's and it didnt work however running two of the applications with one listening to port 40004 and writing to 40005 and one listening to 40005 and writing to 40004 works.
The problem seems to be in the sendb_click where I send the message. It says Receipent not connected.
Error message:
System.net.sockets.socketexception (0x80004005); No connection could be made
because the target machine actively refused it 127.0.0.1:40003
at system.net.sockets.tcpclient..ctor(string hostname,int32 port)
at messenger.form2.sendb_click(object sender, eventargs e) in
D:\Messenger\Messenger\Form2.vb:line 97
:Interface
When connected you can choose a computer that is connected to the network on the right and message it. Im planning on having generated ports or whatever but for testing ive just made 40004 and 40005 the ports.
What is going wrong? Do i have to port forward or something?
below is my code
Imports System.Net.Sockets
Imports System.Threading
Imports System.IO
Imports System.Net.Dns
Imports System.DirectoryServices
Public Class Form2
Class entity
Public name As String
Public ip As String
Public port As Integer
End Class
Public reciepent As New entity
Public user As New entity
Public CLient As New TcpClient
Public listener As New TcpListener(40003)
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
usernametb.Text = user.name
FindingThreats()
getmyip()
ipl.Text = user.ip
user.port = 40003
portl.Text = user.port
' listener = New TcpListener(40004)
Dim ListThread As New Thread(New ThreadStart(AddressOf Listening))
ListThread.Start()
End Sub
Private Sub Listening()
listener.Start()
End Sub
Sub FindingThreats()
UsersL.Items.Clear()
Dim childEntry As DirectoryEntry
Dim ParentEntry As New DirectoryEntry
Try
ParentEntry.Path = "WinNT:"
For Each childEntry In ParentEntry.Children
Select Case childEntry.SchemaClassName
Case "Domain"
Dim SubChildEntry As DirectoryEntry
Dim SubParentEntry As New DirectoryEntry
SubParentEntry.Path = "WinNT://" & childEntry.Name
For Each SubChildEntry In SubParentEntry.Children
Select Case SubChildEntry.SchemaClassName
Case "Computer"
UsersL.Items.Add(SubChildEntry.Name)
End Select
Next
End Select
Next
Catch Excep As Exception
MsgBox("Error While Reading Directories : " + Excep.Message.ToString)
Finally
ParentEntry = Nothing
End Try
End Sub
Sub getmyip()
For Each ip As Net.IPAddress In
GetHostEntry(GetHostName).AddressList
user.ip = ip.ToString
Next
End Sub
Sub getip(strhostname As String, returnip As String)
Try
returnip = GetHostByName(strhostname).AddressList(0).ToString()
reciepent.ip = returnip
Catch
MsgBox("This user is Offline.")
End Try
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles UsersL.SelectedIndexChanged
CUL.Items.Clear()
CUL.Items.Add("Connected Users:")
Dim ip As String
Dim hostname = UsersL.SelectedItem.ToString
getip(hostname, ip)
reciepent.port = 40004
Timer1.Enabled = True
CUL.Items.Add(user.name)
End Sub
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
Me.Close()
End Sub
Private Sub SendB_Click(sender As Object, e As EventArgs) Handles SendB.Click
Try
CLient = New TcpClient("127.0.0.1", 40004) 'reciepent.port)
Dim Writer As New StreamWriter(CLient.GetStream())
Writer.Write(ChatB.Text)
ChatL.Items.Add("> " & ChatB.Text)
Writer.Flush()
Catch
MsgBox("Receipent not connected.")
End Try
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim message As String
If listener.Pending = True Then
message = ""
CLient = listener.AcceptTcpClient()
Dim Reader As New StreamReader(CLient.GetStream())
While Reader.Peek > -1
message = message + Convert.ToChar(Reader.Read()).ToString
End While
ChatL.Items.Add("< " & message)
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
FindingThreats()
End Sub
Private Sub Form2_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
listener.Stop()
Me.Close()
End Sub
End Class

Using SqlDependency with named Queues in vb.net to populate the datagridview each time there is a change in database

Am developing an interface that needs to get data from the database and post to main system in real time.ie when a transcation is initiated in need to hit the main system in realtime for responce fo futher proccessing. i am creating an interface for the application which uses sql server.
i am trying to use the sqldependancy with the following code
Option Strict On
Option Explicit On
Imports System.Data.SqlClient
Imports System.Security.Permissions
mports System.ComponentModel
Public Class Home
Private Sub Home_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'BillPaymentsDataSet.Transactions_Temp' table. You can move, or remove it, as needed.
Me.Transactions_TempTableAdapter.Fill(Me.BillPaymentsDataSet.Transactions_Temp)
End Sub
Private Function GetConnectionString() As String
Return My.Settings.BillPaymentsConnectionString
End Function
Sub Initialization()
Dim con As New SqlConnection(My.Settings.BillPaymentsConnectionString)
SqlDependency.Start(My.Settings.BillPaymentsConnectionString)
End Sub
Private Function CanRequestNotifications() As Boolean
Dim permission As New SqlClientPermission( _
PermissionState.Unrestricted)
Try
permission.Demand()
Return True
Catch ex As Exception
Return False
End Try
End Function
Private Sub GetData()
BillPaymentsDataSet = Nothing
dt = New DataTable()
BillPaymentsDataSet.Clear()
SqlDependency.Stop(GetConnectionString())
SqlDependency.Start(GetConnectionString())
command.Notification = Nothing
If con Is Nothing Then
con = New SqlConnection(GetConnectionString())
End If
Dim dependency As New SqlDependency(command)
AddHandler dependency.OnChange, AddressOf dependency_OnChange
con.Open()
Using Transactions_TempTableAdapter As New SqlDataAdapter(command)
Me.Transactions_TempTableAdapter.Fill(Me.BillPaymentsDataSet.Transactions_Temp)
Me.DataGridView1.DataSource = BillPaymentsDataSet.Transactions_Temp
End Using
End Sub
Private Sub UserMantainanceToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles UserMantainanceToolStripMenuItem.Click
UserMantain.Show()
End Sub
Private Sub dependency_OnChange( _
ByVal sender As Object, ByVal e As SqlNotificationEventArgs)
Dim changeCount As Integer = 0
Const statusMessage As String = _
"{0} changes have occurred."
Dim i As ISynchronizeInvoke = CType(Me, ISynchronizeInvoke)
If i.InvokeRequired Then
' Create a delegate to perform the thread switch
Dim tempDelegate As New OnChangeEventHandler( _
AddressOf dependency_OnChange)
Dim args() As Object = {sender, e}
' Marshal the data from the worker thread
' to the UI thread.
i.BeginInvoke(tempDelegate, args)
Return
End If
' Remove the handler since it's only good
' for a single notification
Dim dependency As SqlDependency = _
CType(sender, SqlDependency)
RemoveHandler dependency.OnChange, _
AddressOf dependency_OnChange
' At this point, the code is executing on the
' UI thread, so it is safe to update the UI.
changeCount += 1
Me.Label1.Text = String.Format(statusMessage, changeCount)
' Add information from the event arguments to the list box
' for debugging purposes only.
With Me.ListBox1.Items
.Clear()
.Add("Info: " & e.Info.ToString())
.Add("Source: " & e.Source.ToString())
.Add("Type: " & e.Type.ToString())
End With
' Reload the dataset that's bound to the grid.
GetData()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
End Sub
End Class

Application with two forms is not showing

I am creating a form application using Visual Studio Express VB 2008 and SQL server 2008. I have two forms. When the program start is not showing me any form. What is to be done that I could use two forms as one program. For example, in one form I want to insert data type state, city .. and the other to use the same information for something else. But like I said, my first step is to see both forms in one program. What should I do to make it work
Imports System.Data.Sql
Imports System.Data.SqlClient
' This is my main form called form1 and through it I want to call a form called Country. Belonging to the same project. How to call a form ,,country,, that I could use
Public Class Form1
Dim objDS As New DataSet
Dim objDA As New SqlDataAdapter
Public Sqlcon As New SqlConnection With {.connectionString = "server=XXX\MSSQL2008;database=TEST;Trusted_Connection=True;"}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If hasConnection() = True Then
MessageBox.Show("uspijesno povezano sa bazom")
End If
getSelc()
End Sub
Public Function hasConnection() As Boolean
Try
Sqlcon.Open()
Sqlcon.Close()
Return True
Catch ex As Exception
MessageBox.Show("Niste povezani sa bazom")
Return False
End Try
End Function
Public Function selc()
Dim objDS = New DataSet
Dim objDA As New SqlDataAdapter
Sqlcon.Close()
Sqlcon.Open()
Dim exCommand As String = ""
Dim myCommand As New SqlCommand
Dim commitTransaction = Sqlcon.BeginTransaction
Try
myCommand = New SqlCommand("EXECUTE " & "regionSelect" & " '" & txtID.EditValue & "', '" & txtShortN.EditValue & "', N'" & txtRegion.EditValue & "', '" & txtStatus.EditValue & "'", Sqlcon)
myCommand.Transaction = commitTransaction
objDA.SelectCommand = myCommand
objDA.Fill(objDS)
commitTransaction.Commit()
Sqlcon.Close()
MessageBox.Show("Podaci su uspijesno poslati")
Catch ex As Exception
MessageBox.Show(ex.Message)
commitTransaction.Rollback()
End Try
End Function
Private Sub SimpleButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
'insert()
End Sub
Private Sub btnConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfirm.Click
getSelc()
End Sub
Public Function getSelc()
objDS = New DataSet
Dim com As New SqlCommand
Sqlcon.Close()
Sqlcon.Open()
GridControl1.DataSource = Nothing
Try
com = New SqlCommand("EXECUTE rS '" & txtID.Text & " ' , ' " & txtRegion.Text & "' , '" & txtShortN.Text & "', ' " & txtStatus.Text & " ' ", Sqlcon)
'com = New SqlCommand("SELECT * FROM tblRegion", Sqlcon)
objDA.SelectCommand = com
objDA.Fill(objDS)
com.CommandType = CommandType.StoredProcedure
GridControl1.DataSource = objDS.Tables(0)
objDA.Dispose()
com.Dispose()
Sqlcon.Close()
MessageBox.Show("Im here")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
'GridControl1.DataSource = Nothing
'objDS.Tables(0).Rows.Clear()
End Function
Private Sub SimpleButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton4.Click
getSelc()
Dim newRow As DataRow
newRow = objDS.Tables(0).NewRow
newRow.Item(0) = txtID.EditValue
newRow.Item(1) = txtShortN.EditValue
newRow.Item(2) = txtRegion.EditValue
newRow.Item(3) = txtStatus.EditValue
objDS.Tables(0).Rows.Add(newRow)
End Sub
Private Sub SimpleButton3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton3.Click
End Sub
Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton1.Click
Country.Show() ' => Is this a good way, and is there any better way and more efficient
End Sub
End Class
You cannot load more than one form on Application Startup. You have to load any one form first then show others from its Form_Load event.
Private Sub StartupForm_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim form2 As New Form2
form2.Show()
Dim form3 As New Form3
form3.Show()
End Sub
Or you can load forms manually on Button Click.
Set the Form1 as a StartupForm from the Project Property Window.
Now, Add a button in your first form button1 and write down some code to display another form.
Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
Dim form2 As New Form2
form2.Show()
End Sub
Another one is calling main method. For that you need to assign Main method in your Project Property Window
Module mainModule
Sub Main()
Dim form2 As New Form2
form2.Show()
Dim form3 As New Form3
form3.ShowDialog()
End Sub
End Module