My data table is loaded in 2 places, a DataGridView and a ComboBox
The ComboBox is to select a record to edit (a TextBox to enter a new value)
And the DataGridView is to see the changes (I gave up (for now) updating directly from the DataGridView)
Private Sub EditLoc_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
con.Open()
Dim sql = Nothing
sql = "SELECT Location FROM Location"
Dim cmdDataGrid As SQLiteCommand = New SQLiteCommand(sql, con)
Dim da As New SQLiteDataAdapter
da.SelectCommand = cmdDataGrid
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
Dim readerDataGrid As SQLiteDataReader = cmdDataGrid.ExecuteReader()
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Try ' TRY CATCH for combobox
con.Open()
cmd.Connection = con
cmd.CommandText = "SELECT Location FROM Location"
dr = cmd.ExecuteReader()
' Fill a combo box with the datareader
Do While dr.Read = True
ComboBox1.Items.Add(dr.GetString(0))
Loop
If ComboBox1.Items.Count > 0 Then
ComboBox1.SelectedIndex = 0 ' The first item has index 0 '
End If
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
This works perfectly
Picture
The problem is when I click Save, the app hangs a while, and then I get the "Database is locked" error picture
Here is the code for the Save button:
Private Sub Savebtn_Click(sender As Object, e As EventArgs) Handles Savebtn.Click
Try
con.Open()
cmd = con.CreateCommand
cmd.CommandText = "UPDATE Location set Location = '" & TextBox1.Text & "' WHERE Location = '" & ComboBox1.Text & "'"
cmd.ExecuteNonQuery()
cmd.Dispose()
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Thanks for the help
I fixed this problem by removing all "cmd.Dispose()", "da.Dispose()" and "con.Close()" from the code, leaving them ONLY in
Private Sub Closebtn_Click(sender As Object, e As EventArgs) Handles Closebtn.Click
da.Dispose()
cmd.Dispose()
con.Close()
Dim fems As New EMS
fems.Show()
Me.Close()
End Sub
On Form Load I have
Private Sub EditLoc_Load(sender As Object, e As EventArgs) Handles MyBase.Load
con.Open()
Call pull()
End Sub
And the Pull sub has all the rest...
Private Sub pull()
Try
Dim sql = Nothing
sql = "SELECT Location FROM Location"
Dim cmdDataGrid As SQLiteCommand = New SQLiteCommand(sql, con)
da.SelectCommand = cmdDataGrid
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
Dim readerDataGrid As SQLiteDataReader = cmdDataGrid.ExecuteReader()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Try ' TRY CATCH for combobox
cmd.Connection = con
cmd.CommandText = "SELECT Location FROM Location"
dr = cmd.ExecuteReader()
' Fill a combo box with the datareader
Do While dr.Read = True
ComboBox1.Items.Add(dr.GetString(0))
Loop
If ComboBox1.Items.Count > 0 Then
ComboBox1.SelectedIndex = 0 ' The first item has index 0 '
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
And here is my Save button
Private Sub Savebtn_Click(sender As Object, e As EventArgs) Handles Savebtn.Click
If Not TextBox1.Text = Nothing Then
Try
cmd = con.CreateCommand
cmd.CommandText = "UPDATE Location set Location = '" & TextBox1.Text & "' WHERE Location = '" & ComboBox1.Text & "'"
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Call pull()
TextBox1.Text = Nothing
End If
End Sub
Now everything is working, no errors!
Calling pull() after saving will update the DataGridView
Thanks for the help
Related
I have a form with retrieved data form ms access database. While updating using the adapter update statement, it shows Syntax error.
The following are the connection code in form load event and update button click event.
could you please let me know whats wrong in this?
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\DESKTOP\VBATESTING\ADPE Project\Project Tables\ADPE_Table.accdb"
inc = 0
Dim Con As New OleDbConnection()
Dim Cmd As New OleDbCommand
Dim SQL As String = "SELECT * FROM Heidelberg"
Con.ConnectionString = strConn
Try
Con.Open()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Cmd = New OleDbCommand(SQL, Con)
Adapter.SelectCommand = New OleDbCommand(SQL, Con)
ds = New DataSet
Adapter.Fill(ds, "testing")
MaxRows = ds.Tables("testing").Rows.Count
Label1.Text = "Total Records :" & MaxRows
NavigateRecords()
End Sub
Private Sub UpdateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
Dim cb As New OleDb.OleDbCommandBuilder(Adapter)
ds.Tables("testing").Rows(inc).Item(5) = TextBox1.Text
ds.Tables("testing").Rows(inc).Item(2) = TextBox2.Text
ds.Tables("testing").Rows(inc).Item(3) = TextBox3.Text
ds.Tables("testing").Rows(inc).Item(4) = TextBox4.Text
Try
Adapter.Update(ds, "testing")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
You have way too many commands in your Form.Load.
One
Dim Cmd As New OleDbCommand
Two
Cmd = New OleDbCommand(SQL, Con)
Three
Adapter.SelectCommand = New OleDbCommand(SQL, Con)
Every time you use the New keyword, you create another command.
If you are only dealing with a single table, you don't need a DataSet. The extra object adds extra weight and complicates the code a bit.
Private inc As Integer
Private Adapter As New OleDbDataAdapter
Private MaxRows As Integer
Private dat As New DataTable
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim strConn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\DESKTOP\VBATESTING\ADPE Project\Project Tables\ADPE_Table.accdb"
inc = 0
Using Con As New OleDbConnection(strConn)
Using Cmd As New OleDbCommand("SELECT * FROM Heidelberg;", Con)
Adapter.SelectCommand = Cmd
Try
Adapter.Fill(dat)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Using
End Using
MaxRows = dat.Rows.Count
Label1.Text = "Total Records :" & MaxRows
NavigateRecords()
End Sub
Private Sub UpdateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
dat.Rows(inc).Item(5) = TextBox1.Text
dat.Rows(inc).Item(2) = TextBox2.Text
dat.Rows(inc).Item(3) = TextBox3.Text
dat.Rows(inc).Item(4) = TextBox4.Text
Dim cb As New OleDbCommandBuilder(Adapter)
'This will take care of any spaces that you have in column names.
cb.QuotePrefix = "["
cb.QuoteSuffix = "]"
Try
Adapter.Update(dat)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
This are my code, It worked perfectly except for ONE. I can't update:
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Dim con As SqlConnection
Dim Cmd As SqlCommand
Dim Query As String
Sub disk()
con = New SqlConnection
con.ConnectionString = "Server=Jansen\SQLEXPRESS;Database=AJLMNewProjectDatabase;Trusted_Connection=True;"
Try
con.Open()
Dim READER As SqlDataReader
Query = "UPDATE AdminESP SET Benefactor='" & CmbBenefactor.Text & "' WHERE ExternalSP='" & CmbExternalSP.Text & "'"
Cmd = New SqlCommand(Query, con)
READER = Cmd.ExecuteReader()
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
con.Close()
End Try
con.Close()
End Sub
Sub dis()
CmbExternalSP.Items.Clear()
CmbBenefactor.Items.Clear()
con = New SqlConnection
con.ConnectionString = "Server=Jansen\SQLEXPRESS;Database=AJLMNewProjectDatabase;Trusted_Connection=True;"
Try
con.Open()
Dim READER As SqlDataReader
Query = "select * from [AJLMNewProjectDatabase].[dbo].[AdminESP]"
Cmd = New SqlCommand(Query, con)
READER = Cmd.ExecuteReader()
While READER.Read
Dim ESP = READER.GetString(1)
Dim Ben = READER.GetString(2)
CmbExternalSP.Items.Add(ESP)
CmbBenefactor.Items.Add(Ben)
End While
con.Close()
Catch ex As SqlException
MessageBox.Show(ex.Message)
Finally
con.Dispose()
End Try
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
con = New SqlConnection
con.ConnectionString = "Server=Jansen\SQLEXPRESS;Database=AJLMNewProjectDatabase;Trusted_Connection=True;"
Try
con.Open()
Dim READER As SqlDataReader
Query = "select * from AdminESP"
Cmd = New SqlCommand(Query, con)
READER = Cmd.ExecuteReader()
While READER.Read
Dim ESP = READER.GetString(1)
Dim Ben = READER.GetString(2)
CmbExternalSP.Items.Add(ESP)
CmbBenefactor.Items.Add(Ben)
End While
con.Close()
Catch ex As SqlException
MessageBox.Show(ex.Message)
Finally
con.Dispose()
End Try
End Sub
Private Sub CmbExternalSP_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CmbExternalSP.SelectedIndexChanged
CmbBenefactor.SelectedIndex = CmbExternalSP.SelectedIndex
End Sub
Private Sub BtnAdd_Click(sender As Object, e As EventArgs) Handles BtnAdd.Click
con = New SqlConnection("Server=Jansen\SQLEXPRESS;Database=AJLMNewProjectDatabase;Trusted_Connection=True;")
con.Open()
Cmd = con.CreateCommand
Cmd.CommandText = String.Format("INSERT INTO AdminESP(ExternalSP, Benefactor) " &
"VALUES('{0}', '{1}')",
CmbExternalSP.Text,
CmbBenefactor.Text) ' To Save data to ExternalSP DataTable
Dim rowsAffected As Integer = Cmd.ExecuteNonQuery()
If rowsAffected > 0 Then
MsgBox("Program Added!")
Else
MsgBox("Failed to Add")
End If
CmbExternalSP.Text = ""
CmbBenefactor.Text = ""
con.Close()
End Sub
Private Sub BtnRefresh_Click(sender As Object, e As EventArgs) Handles BtnRefresh.Click
CmbExternalSP.DropDownStyle = ComboBoxStyle.DropDown
CmbBenefactor.DropDownStyle = ComboBoxStyle.DropDown
CmbExternalSP.Text = ""
CmbBenefactor.Text = ""
End Sub
Private Sub BtnRemove_Click(sender As Object, e As EventArgs) Handles BtnRemove.Click
con = New SqlConnection
con.ConnectionString = "Server=Jansen\SQLEXPRESS;Database=AJLMNewProjectDatabase;Trusted_Connection=True;"
Try
con.Open()
Dim READER As SqlDataReader
Query = "DELETE FROM AdminESP WHERE ExternalSP='" + CmbExternalSP.Text + "'"
Cmd = New SqlCommand(Query, con)
READER = Cmd.ExecuteReader()
If MessageBox.Show("You are about to remove a Program, Please confirm your Action.", "DELETE", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.OK Then
MsgBox("Program Removed")
End If
CmbExternalSP.Text = ""
CmbBenefactor.Text = ""
CmbExternalSP.DropDownStyle = ComboBoxStyle.DropDownList
CmbBenefactor.DropDownStyle = ComboBoxStyle.DropDownList
Call dis()
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
con.Close()
End Try
con.Close()
End Sub
Private Sub BtnUpdate_Click(sender As Object, e As EventArgs) Handles BtnUpdate.Click
con = New SqlConnection
con.ConnectionString = "Server=Jansen\SQLEXPRESS;Database=AJLMNewProjectDatabase;Trusted_Connection=True;"
Try
con.Open()
Dim READER As SqlDataReader
Query = "UPDATE AdminESP SET ExternalSP='" & CmbExternalSP.Text & "' WHERE Benefactor='" & CmbBenefactor.Text & "'"
Cmd = New SqlCommand(Query, con)
READER = Cmd.ExecuteReader()
MessageBox.Show("Program Updated.")
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
con.Close()
End Try
con.Close()
End Sub
Private Sub BtnR_Click(sender As Object, e As EventArgs) Handles BtnR.Click
Call dis()
End Sub
Private Sub CmbBenefactor_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CmbBenefactor.SelectedIndexChanged
CmbExternalSP.SelectedIndex = CmbBenefactor.SelectedIndex
End Sub
End Class
Now my problem is, When I click UPDATE button, only one column which is under combobox 1 updates; the other combobox doesn't change at all.
I use following code to update database record after retrieving data to the text boxes via a datagridview.
But this gives me an exception as object reference not set to an instance of the object. Please help
Private Sub DataGridView_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridViewUserType.CellClick
Dim i As Integer
i = DataGridViewUserType.CurrentRow.Index
If i >= 0 Then
Me.txtBoxID.Text = DataGridViewUserType.Item(0, i).Value
Me.txtBoxUserType.Text = DataGridViewUserType.Item(1, i).Value
Else
MessageBox.Show("Empty Row Clicked")
End If
End Sub
Private Sub btnUserTypeUpdate_Click(sender As Object, e As EventArgs) Handles btnUserTypeUpdate.Click
Try
con.Open()
cmd.Connection = con
cmd.CommandText = "UPDATE dbo.User_Type SET Type = #tp WHERE Type_ID = #ID"
cmd.Parameters.AddWithValue("#ID", txtBoxID.Text)
cmd.Parameters.AddWithValue("#tp", txtBoxUserType.Text)
cmd.ExecuteNonQuery()
MessageBox.Show("Successfully Updated")
Catch ex As Exception
MessageBox.Show("Error while inserting record on table..." & ex.Message, "Update Records")
Finally
con.Close()
btnUserTypeSave.Show()
txtBoxID.Clear()
txtBoxUserType.Clear()
End Try
End Sub
Thankz Fabio
The error was with "cmd"
I just put Dim cmd As SqlCommand = New SqlCommand before using it and now it is functioning.
Thankz All
I have a form , which have 1 combobox and 1 textbox.
and a table named tbl_dress which have columns as Dress_ID, Dress_Name, Dress_Price..
the combobox shows the Dress_Name and the code works..
Code for the combobox :-
Private Sub FillCombo()
Try
Dim fillcon As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\annonymous\Documents\Visual Studio 2012\Projects\DressTest\DressTest\db\PriceTesting.accdb")
Dim query As String = ("SELECT Dress_Name FROM tbl_dress")
Dim da As New OleDb.OleDbDataAdapter(query, fillcon)
Dim ds As New DataSet
da.Fill(ds)
ComboBox1.ValueMember = "Dress_Name"
ComboBox1.DataSource = ds.Tables(0)
ComboBox1.SelectedIndex = 0
Catch ex As Exception
MsgBox("ERROR : " & ex.Message.ToString)
End Try
End Sub
and this is the code when my form is loaded :-
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Dim con As New OleDb.OleDbConnection
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\annonymous\Documents\Visual Studio 2012\Projects\TMS Final\TMS Final\db\db_TMS.accdb"
con.Open()
FillCombo() ' Display data from tbl_order on form load
con.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
so the question is , how do i get the Dress_Price , determined by the Dress_Name chosen on the combobox.
i have tried the following code , but i have errors.
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Try
Dim fillcon As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\annonymous\Documents\Visual Studio 2012\Projects\DressTest\DressTest\db\PriceTesting.accdb")
fillcon.Open()
Dim query As String = ("SELECT Dress_Price FROM tbl_dress WHERE Dress_Name = ' " & ComboBox1.SelectedValue.ToString & " ' ")
Dim cmd As New OleDb.OleDbCommand(query, fillcon)
cmd.CommandText = query
TextBox1.Text = cmd.ExecuteScalar().ToString()
fillcon.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
so where did i go wrong and what should i do? new to vb.net
Try this line on execution
TextBox1.Text= Convert.ToInt32(cmd.ExecuteScalar()).ToString()
My question was whether ur getting the desired value at that point
can you put stopper near the below method and see the return value
Dim query As String = ("SELECT Dress_Price FROM tbl_dress WHERE Dress_Name = ' " & ComboBox1.SelectedValue.ToString & " ' ")
try to hard code the dress name and check. Also try Select Top 1
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Try
Dim fillcon As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\annonymous\Documents\Visual Studio 2012\Projects\DressTest\DressTest\db\PriceTesting.accdb")
fillcon.Open()
Dim query As String = ("SELECT Dress_Price FROM tbl_dress WHERE Dress_Name = ' " & ComboBox1.Text & " ' ")
Dim cmd As New OleDb.OleDbCommand(query, fillcon)
cmd.CommandText = query
TextBox1.Text = cmd.ExecuteScalar().ToString()
fillcon.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
I can't Search and Edit using this Code. Insert is working. But Insert coding method is not sure (fileContent.ToString). And Search part and Update part is not working.
Dim fileContent As Byte() = My.Computer.FileSystem.ReadAllBytes(OpenFileDialog1.FileName)
Sub NormalUpdate(ByVal _Query)
con.Open()
Dim cmdUpdate As New SqlCommand(_Query)
cmdUpdate.Connection = con
cmdUpdate.CommandType = CommandType.Text
cmdUpdate.ExecuteNonQuery()
con.Close()
End Sub
Sub NormalSave(ByVal _Query)
con.Open()
Dim cmdSave As New SqlCommand(_Query)
cmdSave.Connection = con
cmdSave.CommandType = CommandType.Text
cmdSave.ExecuteNonQuery()
con.Close()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
NormalSave("Insert into Registration values('" + txtMemberNo.Text + "','" + fileContent.ToString + "')")
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
con.Open()
Using cmd As New SqlClient.SqlCommand("Select MemberPicture From Registration where MemberNo = '" + txtMemberNo.Text + "'", con)
Using dr As SqlClient.SqlDataReader = cmd.ExecuteReader()
Using dt As New DataTable
dt.Load(dr)
Dim row As DataRow = dt.Rows(0)
Using ms As New IO.MemoryStream(CType(row("MemberPicture"), Byte()))
Dim img As Image = Image.FromStream(ms)
ProfilePic.Image = img
con.Close()
End Using
End Using
End Using
End Using
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
NormalUpdate("Update Registration set MemberPicture = '" + fileContent.ToString + "' where MemberNo = '" + txtMemberNo.Text + "'")
End Sub
Please help me. Thanks.
Not sure if this is what you are looking for, but I use the following to get and set images from a database:
Public Function GetClientImage(ID As String) As Image
Dim ClientPicture As Image = Nothing
Dim DS As DataSet = Nothing
'Populate DS here
If (DS IsNot Nothing) AndAlso (DS.Tables.Count > 0) AndAlso (DS.Tables(0).Rows.Count > 0) Then
Dim DR As DataRow = DS.Tables(0).Rows(0)
Try
Dim Pic As Object = DR!Picture
If Pic IsNot DBNull.Value Then
Dim Buffer As Byte() = CType(DR!Picture, Byte())
If Buffer IsNot Nothing AndAlso (Buffer.Length > 0) Then
Using MS As New IO.MemoryStream(Buffer, 0, Buffer.Length)
MS.Write(Buffer, 0, Buffer.Length)
ClientPicture = Image.FromStream(MS, True)
End Using
End If
End If
Catch ex As Exception
MessageBox.Show("Error retrieving Image: " & ControlChars.NewLine & ControlChars.NewLine & ex.ToString, My.Application.Info.AssemblyName, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
End Try
End If
Return ClientPicture
End Function
and:
Public Function UpdateClientImage(ID As String, Pic As Image) As Integer
Dim Result As Integer = 0
If Client IsNot Nothing Then
Dim SQL As String = "UPDATE Clients SET Picture = #photo WHERE ID = '" & ID & "' ;"
Using SQLConn As New SqlClient.SqlConnection(ConnectionString)
Try
SQLConn.Open()
Using SQLCmd As New SqlClient.SqlCommand(SQL, SQLConn)
Dim PhotoParameter As New SqlClient.SqlParameter("#photo", SqlDbType.Image)
Dim MS As New IO.MemoryStream()
If Pic IsNot Nothing Then
Pic.Save(MS, Imaging.ImageFormat.Bmp)
End If
PhotoParameter.SqlValue = MS.GetBuffer
SQLCmd.Parameters.Add(PhotoParameter)
Result = SQLCmd.ExecuteNonQuery()
End Using
Catch ex As Exception
Dim Msg As String = "Unable to save Client's Picture"
If ex IsNot Nothing Then
Msg &= ":" & ControlChars.NewLine & ControlChars.NewLine & ex.ToString
End If
MessageBox.Show(Msg, My.Application.Info.AssemblyName, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
Finally
If Not SQLConn.State = ConnectionState.Closed Then
SQLConn.Close()
End If
End Try
End Using
End If
Return Result
End Function
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles
Dim OpennFileDialog As OpenFileDialog
query = "update tblEmployeeSetup set dbImage = #dbImage where empy_id = '" + txtEmpId.Text + "' "
insertImage(query, "Data Saved...", lblSave, OpennFileDialog )
End Sub
Sub insertImage(ByVal query As String, ByVal message As String, ByVal lblSave As Label, ByVal a As OpenFileDialog)
Try
If con.State = ConnectionState.Closed Then
con.Open()
End If
' Dim result As DialogResult = a.ShowDialog()
' a.FileName = My.Resources.DefultImage.ToString
cmd.Connection = con
cmd.CommandText = query
cmd.Parameters.Add(New SqlClient.SqlParameter("#dbimage", SqlDbType.Image)).Value = IO.File.ReadAllBytes(a.FileName)
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
lblSave.Text = message
a.Dispose()
Catch ex As Exception
MessageBox.Show("Error" & ex.Message)
Finally
con.Close()
End Try
End Sub