How to update an Access DB from a DataGridView in Visual Basic - vb.net

I am creating an inventory application which runs off of an Access DB in visual studio, using visual basic. I can populate my data grid view just fine, but when I try to add new information into the data grid view, it does not number correctly and it does not append my database.
I have tried binding and updating using the table adapter.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
CustomersBindingSource.AddNew()
Me.Validate()
Me.CustomersTableAdapter.Update(Me.Database1DataSet.Customers)
Me.CustomersBindingSource.EndEdit()
End Sub
Here is my code:
Public Class Form1
Private Sub enterbtn_Click(sender As Object, e As EventArgs) Handles enterbtn.Click
If username.Text = "Tanner" And password.Text = "bmis365" Then
GroupBox1.Visible = False
Else
MsgBox("Incorrect Username or Password, please try again.")
username.Clear()
password.Clear()
username.Focus()
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.CurrentCell = Nothing
'This line of code loads data into the 'Database1DataSet.Customers' table. You can move, or remove it, as needed.
Me.CustomersTableAdapter.Fill(Me.Database1DataSet.Customers)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'This is where my new info is to be appended into the database, once the button is clicked.
CustomersBindingSource.AddNew()
Me.Validate()
Me.CustomersTableAdapter.Update(Me.Database1DataSet.Customers)
Me.CustomersBindingSource.EndEdit()
End Sub
Private Sub searchbtn_Click(sender As Object, e As EventArgs) Handles searchbtn.Click
'The Following Code is from https://social.msdn.microsoft.com/Forums/vstudio/en-US/36c54726-4f49-4e15-9597-7b201ec13ae7/search-in-datagrid-using-textbox-vbnet-without-data-connectivity?forum=vbgeneral
For Each row As DataGridViewRow In DataGridView2.Rows
For Each cell As DataGridViewCell In row.Cells
If Not IsNothing(cell.Value) Then
If cell.Value.ToString.StartsWith(searchbar.Text, StringComparison.InvariantCultureIgnoreCase) Then
cell.Selected = True
DataGridView2.CurrentCell = DataGridView2.SelectedCells(0)
End If
End If
Next
Next
End Sub
End Class
My output initially has 3 rows(numbered 1, 2, and 3) but any that are added through the application have the numbers -1, -2, -3 and so on. Also, when I close the program and restart it, my original rows (1, 2, and 3) are still there from when I entered them in the DB file, but any that were added through my application are gone.

Here is one way to do an Update, as well as a few other common SQL manipulations/operations.
Imports System.Data.SqlClient
Public Class Form1
Dim sCommand As SqlCommand
Dim sAdapter As SqlDataAdapter
Dim sBuilder As SqlCommandBuilder
Dim sDs As DataSet
Dim sTable As DataTable
Private Sub load_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles load_btn.Click
Dim connectionString As String = "Data Source=.;Initial Catalog=pubs;Integrated Security=True"
Dim sql As String = "SELECT * FROM Stores"
Dim connection As New SqlConnection(connectionString)
connection.Open()
sCommand = New SqlCommand(sql, connection)
sAdapter = New SqlDataAdapter(sCommand)
sBuilder = New SqlCommandBuilder(sAdapter)
sDs = New DataSet()
sAdapter.Fill(sDs, "Stores")
sTable = sDs.Tables("Stores")
connection.Close()
DataGridView1.DataSource = sDs.Tables("Stores")
DataGridView1.ReadOnly = True
save_btn.Enabled = False
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
End Sub
Private Sub new_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles new_btn.Click
DataGridView1.[ReadOnly] = False
save_btn.Enabled = True
new_btn.Enabled = False
delete_btn.Enabled = False
End Sub
Private Sub delete_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delete_btn.Click
If MessageBox.Show("Do you want to delete this row ?", "Delete", MessageBoxButtons.YesNo) = DialogResult.Yes Then
DataGridView1.Rows.RemoveAt(DataGridView1.SelectedRows(0).Index)
sAdapter.Update(sTable)
End If
End Sub
Private Sub save_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save_btn.Click
sAdapter.Update(sTable)
DataGridView1.[ReadOnly] = True
save_btn.Enabled = False
new_btn.Enabled = True
delete_btn.Enabled = True
End Sub
End Class

Related

Save row colour after closing form

I got this for saving all data when closing the form.
Public Class Form1
Dim table As New DataTable("Table")
ReadOnly p As String = Path.Combine("C:\test.xml")
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
If Not File.Exists(p) Then
table.Columns.Add("Company", Type.GetType("System.String"))
table.Columns.Add("Date", Type.GetType("System.DateTime"))
table.Columns.Add("Code", Type.GetType("System.String"))
table.Columns.Add("Position", Type.GetType("System.String"))
table.Columns.Add("Note", Type.GetType("System.String"))
table.Columns.Add("Solved", Type.GetType("System.DateTime"))
Else
table.ReadXml(p)
End If
DataGridView1.DataSource = table
End Sub
I was using this for mark solved row:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
DataGridView1.CurrentRow.DefaultCellStyle.BackColor = Color.PaleGreen
DataGridView1.CurrentRow.Cells("Solved").Value = DateTime.Now
DataGridView1.DataSource = table
DataGridView1.ClearSelection()
End Sub
And this for "repair solved row" button:
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
DataGridView1.CurrentRow.DefaultCellStyle.BackColor = Color.White
DataGridView1.CurrentRow.Cells("Solved").Value = ""
DataGridView1.DataSource = table
DataGridView1.ClearSelection()
End Sub
The problem is, that my saving doesn't save this coloured row, it's white when I open the form again.
Any idea? I'm really new to this.
Thanks.
The following code should color the rows as described in my comments.
Private Sub ColorRows()
For Each row As DataGridViewRow In DataGridView1.Rows
If (Not row.IsNewRow) And (row.Cells("Solved").Value IsNot DBNull.Value) Then
row.DefaultCellStyle.BackColor = Color.PaleGreen
End If
Next
End Sub
You could call this code in the forms Load event right after the data has been loaded into the grid. Something like…
….
DataGridView1.DataSource = table
ColorRows()
Edit...
After some testing, it appears that when the code is setting the "Solved" value to an empty string, in the Button4_Click event with...
DataGridView1.CurrentRow.Cells("Solved").Value = ""
This is setting a default min Date value as you noted in the xml file.
Change this line of code to...
DataGridView1.CurrentRow.Cells("Solved").Value = DBNull.Value
It should work as expected then.
Below is the complete code I used to test this.
Dim table As New DataTable("Table")
ReadOnly p As String = Path.Combine("D:\Test\XML\_test_100.xml")
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
If Not File.Exists(p) Then
table.Columns.Add("Company", Type.GetType("System.String"))
table.Columns.Add("Date", Type.GetType("System.DateTime"))
table.Columns.Add("Code", Type.GetType("System.String"))
table.Columns.Add("Position", Type.GetType("System.String"))
table.Columns.Add("Note", Type.GetType("System.String"))
table.Columns.Add("Solved", Type.GetType("System.DateTime"))
Else
table.ReadXml(p)
End If
DataGridView1.DataSource = table
ColorRows()
End Sub
Private Sub ColorRows()
For Each row As DataGridViewRow In DataGridView1.Rows
If (Not row.IsNewRow) And (row.Cells("Solved").Value IsNot DBNull.Value) Then
row.DefaultCellStyle.BackColor = Color.PaleGreen
End If
Next
End Sub
Private Sub btnWriteToXML_Click(sender As Object, e As EventArgs) Handles btnWriteToXML.Click
table.WriteXml(p, XmlWriteMode.WriteSchema)
End Sub
Private Sub btnSolved_Click(sender As Object, e As EventArgs) Handles btnSolved.Click
DataGridView1.CurrentRow.DefaultCellStyle.BackColor = Color.PaleGreen
DataGridView1.CurrentRow.Cells("Solved").Value = DateTime.Now
'DataGridView1.DataSource = table
DataGridView1.ClearSelection()
End Sub
Private Sub btnRepairSolved_Click(sender As Object, e As EventArgs) Handles btnRepairedSolved.Click
DataGridView1.CurrentRow.DefaultCellStyle.BackColor = Color.White
DataGridView1.CurrentRow.Cells("Solved").Value = DBNull.Value
'DataGridView1.DataSource = table
DataGridView1.ClearSelection()
End Sub

Parameter Field current value exception was Unhandled

I'm having a problem in my program that when i click the print button it always show up this error Sample error and i don't know what to do now.
this is the code, this is my parameters sample parameters
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CrystalReportViewer1.ShowPrintButton = False
For Each ctrl As Control In CrystalReportViewer1.Controls
If TypeOf ctrl Is Windows.Forms.ToolStrip Then
Dim btnNew As New ToolStripButton
btnNew.Text = "PRINT"
btnNew.ToolTipText = "Print Reciept"
CType(ctrl, ToolStrip).Items.Insert(0, btnNew)
AddHandler btnNew.Click, AddressOf printClick
End If
Next
End Sub
Private Sub printClick(sender As Object, e As EventArgs)
Dim PrintDialog As New PrintDialog
If PrintDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
CrystalReport11.PrintOptions.PrinterName = PrintDialog.PrinterSettings.PrinterName
CrystalReport11.PrintToPrinter(1, False, 0, 0) 'this is where the error coming up'
Transact()
End If
End Sub
Private Sub btnSlip_Click(sender As Object, e As EventArgs) Handles btnSlip.Click
Dim reportDocument As CrystalDecisions.CrystalReports.Engine.ReportDocument
reportDocument = New CrystalReport1
reportDocument.Refresh()
reportDocument.SetDataSource(dt)
reportDocument.SetParameterValue(0, ComboBox2.Text)
reportDocument.SetParameterValue(1, TextBox1.Text)
Form2.CrystalReportViewer1.ReportSource = reportDocument
Form2.ShowDialog()
Form2.Dispose()
Form2.WindowState = FormWindowState.Maximized
End Sub

how to link seat reservation project using vb.net with access database

I have a code for seat reservation but i don't know how to link it with access database. I am using buttons as seats so when a seat is selected it hides itself so i want help when the seat is selected the seat number shows in access database .Here is my code :
Public Class Form1
Dim seatnumber As char
Private Sub BTNA1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNA1.Click
seatnumber = "A1"
Confirmseat()
End Sub
Private Sub BTNA2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNA2.Click
seatnumber = "A2"
confirmseat()
End Sub
Private Sub BTNA3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNA3.Click
seatnumber = "A3"
Confirmseat()
End Sub
Private Sub BTNA4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNA4.Click
seatnumber = "A4"
Confirmseat()
End Sub
Private Sub BTNA5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNA5.Click
seatnumber = "A5"
Confirmseat()
End Sub
Private Sub BTNA6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNA6.Click
seatnumber = "A6"
Confirmseat()
End Sub
Private Sub BTNB7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNB7.Click
seatnumber = "B7"
confirmseat()
End Sub
Private Sub BTNB8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNB8.Click
seatnumber = "B8"
confirmseat()
End Sub
Private Sub BTNB9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNB9.Click
seatnumber = "B9"
confirmseat()
End Sub
Private Sub BTNB10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnb10.Click
seatnumber = "B10"
confirmseat()
End Sub
Private Sub BTNB11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnb11.Click
seatnumber = "B11"
confirmseat()
End Sub
Private Sub BTNB12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnb12.Click
seatnumber = "B12"
confirmseat()
End Sub
Public Sub confirmseat()
Dim intresult As Integer
intresult = MessageBox.Show("you selected" & seatnumber, "CONFIRM", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If intresult = Windows.Forms.DialogResult.No Then
seatnumber = "NO"
Else
Select Case (seatnumber)
Case "A1"
BTNA1.Visible = False
Case "A2"
BTNA2.Visible = False
Case "A3"
BTNA3.Visible = False
Case "A4"
BTNA4.Visible = False
Case "A5"
BTNA5.Visible = False
Case "A6"
BTNA6.Visible = False
Case "B7"
BTNB7.Visible = False
Case "B8"
BTNB8.Visible = False
Case "B9"
BTNB9.Visible = False
Case "B10"
btnb10.Visible = False
Case "B11"
btnb11.Visible = False
Case "B12"
btnb12.Visible = False
End Select
MessageBox.Show("Seat" & seatnumber & "is confirmed", "confirmation")
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim seatavailability As Integer
If seatavailability <> "12" Then
BTNA1.Visible = True
BTNA2.Visible = True
BTNA3.Visible = True
BTNA4.Visible = True
BTNA5.Visible = True
BTNA6.Visible = True
BTNB7.Visible = True
BTNB8.Visible = True
BTNB9.Visible = True
btnb10.Visible = True
btnb11.Visible = True
btnb12.Visible = True
Dim i As Integer
Dim reservedseats(1) As Char
For i = 0 To 12
Select Case (reservedseats(1))
Case "BTNA1"
BTNA1.Visible = False
Case "BTNA2"
BTNA2.Visible = False
Case "BTNA3"
BTNA3.Visible = False
Case "BTNA4"
BTNA4.Visible = False
Case "BTNA5"
BTNA5.Visible = False
Case "BTNA6"
BTNA6.Visible = False
Case "BTNB7"
BTNB7.Visible = False
Case "BTNB8"
BTNB8.Visible = False
Case "BTNB9"
BTNB9.Visible = False
Case "BTNB10"
btnb10.Visible = False
Case "BTNB11"
btnb11.Visible = False
Case "BTNB12"
btnb12.Visible = False
End Select
Next
End If
End Sub
Private Sub btncontinue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncontinue.Click
Me.Close()
End Sub
End Class
Note that you have a LOT of duplicate code. You could simplify your code by writing a single button click handler that forwards the button to ConfirmSeat:
Private Sub ClickHandler(sender As Object, e As EventArgs)
Dim seatNumber = Mid(DirectCast(sender, Button).Name, 4)
ConfirmSeat(seatNumber)
End Sub
and write ConfirmSeat as follows:
Private Sub ConfirmSeat(seatNumber As String)
Dim result As Integer
result = MessageBox.Show("you selected" & seatnumber, "CONFIRM", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If intresult = Windows.Forms.DialogResult.No Then
MessageBox.Show("No seat confirmed")
Exit Sub
End If
Dim btn As Button = Controls("btn" & seatNumber)
btn.Visible = False
MessageBox.Show($"Seat {seatNumber} is confirmed", "confirmation")
End Sub
I'm not quite sure what you are trying to do in the Form1_Load, as none of the Select Case will ever be hit. In any event, the handler could be attached to the Click event of the buttons as follows:
For Each ctrl As Control In Controls
If Not TypeOf ctrl Is Button Then Continue
If ctrl Is btnClick Then Continue
AddHandler DirectCast(ctrl, Button).Click, ClickHandler
Next
With that out of the way, we can talk about reading and writing from / to an Access database in your program, using ADO.NET.
Connections and Execute* methods
At the lowest level, you use a connection string:
Dim connectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" &
"Data Source=" & pathToDatabase
to connect to the database with an OleDbConnection:
Using connection AS New OleDbConnection(connectionString)
connection.Open
' do stuff here
End Using
With an open connection, you can execute commands using an OleDbCommand. You can use commands together with the ExecuteNonQuery method to perform update queries:
Dim cmdDeleteAll As New OleDbCommand("DELETE * FROM Persons", connection)
cmdDeleteAll.ExecuteNonQuery
or together with the ExecuteScalar method, to return a single result:
Dim cmdCount As New OleDbCommand("SELECT COUNT(*) FROM Persons", connection)
Dim count As Integer? = cmdCount.ExecuteScalar
or using the ExecuteReader method, return an OleDbDataReader, to iterate once over a set of results -- forward-only.
Using cmd As New OleDbCommand("SELECT * FROM Persons", connection),
rdr = cmd.ExecuteReader
Do While rdr.Read
MessageBox.Show($"{rdr["FirstName"]} {rdr["LastName"]}")
Loop
End Using
Adapters and DataSets
An OleDbDataReader has access to one record at a tine, from a single result set. If you want to load the data from multiple result sets, or you need to keep all the data in memory, you can use the OleDbDataAdapter to load data into a DataSet from an OleDbConnection object:
Dim ds = new DataSet();
Using connection As New OleDbConnection(connectionString)
Dim sql = "SELECT * FROM Persons"
Dim adapter = new OleDbDataAdapter(sql, connection)
adapter.Fill(ds, "Persons")
End Using
Since a DataSet can contain multiple sets of data, there is a hierarchy of objects for working with the DataSets and its DataTables:
(Source: ADO.NET Architecture)
LINQ against a DataReader
You can also use LINQ and LINQ methods on a data reader, to retrieve a set of objects from a single result set:
Dim persons As List(Of Person)
Using reader = cmd.ExecuteReader()
persons = reader.Cast<DbDataRecord>()
.Select(Function(row) New Person With {
.LastName = row["LastName"])
.FirstName = row["FirstName"]
}).ToList
End Using

Why is does this error happen? "No value given for one or more required parameters"

When I try to click the Button1 ,2 and 3. The error that is stated below happens. This error always occur when I have two tables on my database.
No value given for one or more required parameters
This is my code
Imports System.Data.OleDb
Module MSAccessConnection
Public Function OpenConnection() As String
Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=G:\MerdoresNew\OrderData.accdb"
Return connString
End Function
End Module
Public Class Order
Public total As Integer
Public ordered As Integer
Public ordered2 As Integer
Public ordered3 As Integer
Public price As Integer
Dim myConnection As OleDbConnection = New OleDbConnection
Private Sub Order_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'OrderDatabaseDataSet.Items' table. You can move, or remove it, as needed.
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myConnection.ConnectionString = OpenConnection()
myConnection.Open()
'the query:
Dim cmd As OleDbCommand = New OleDbCommand("SELECT [Price] FROM [Items] where Item='Cheese Burger'", myConnection)
Dim dr As OleDbDataReader = cmd.ExecuteReader
' the following variable is hold true if user is found, and false if user is not found
Dim Found As Boolean = False
While dr.Read
Found = True
price = dr("Price")
End While
If Found = True Then
ordered = TextBox1.Text * price
Else
MsgBox("Saved!")
Me.Close()
End If
myConnection.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
myConnection.ConnectionString = OpenConnection()
myConnection.Open()
'the query:
Dim cmd As OleDbCommand = New OleDbCommand("SELECT [Price] FROM [Items] where Item='Ham Burger'", myConnection)
Dim dr As OleDbDataReader = cmd.ExecuteReader
' the following variable is hold true if user is found, and false if user is not found
Dim Found As Boolean = False
While dr.Read
Found = True
price = dr("Price")
End While
If Found = True Then
ordered2 = TextBox2.Text * price
Else
MsgBox("Saved!")
End If
myConnection.Close()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
total = ordered + ordered2 + ordered3
Form1.TextBox1.Text = total
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
myConnection.ConnectionString = OpenConnection()
myConnection.Open()
'the query:
Dim cmd As OleDbCommand = New OleDbCommand("SELECT [Price] FROM [Items] where Item='Chicken Sandwich'", myConnection)
Dim dr As OleDbDataReader = cmd.ExecuteReader
' the following variable is hold true if user is found, and false if user is not found
Dim Found As Boolean = False
While dr.Read
Found = True
price = dr("Price")
End While
If Found = True Then
ordered3 = TextBox3.Text * price
Else
MsgBox("Saved!")
End If
myConnection.Close()
End Sub
End Class
I don't see where you are passing your connection string to the button click handler. You DIM the connection string as connString, but you never call it in the handler.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myConnection.ConnectionString = OpenConnection() <----- Change ConnectionString to connString
myConnection.Open()
I think that's the variable that you're missing. I would have commented but I don't have enough rep to comment yet.

Vb.net Editing DatagridView

I created a simple program where I can search through a database table. Add data and remove data through a button. Now I want to be able to update the data within the datagrid view however i am getting the classic error: Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.
I have the primary key in the data grid that is not attached to anything in the vb.net program nor in the database at this time. I am not sure what I am missing.
Public Class Form1
Dim cn As New SqlConnection("Data Source=;Initial Catalog=Inventory;User ID=;Password=")
Dim adap As New SqlDataAdapter("SELECT res_snbr, First_Name, Last_Name, Item FROM Inventory_Details", cn)
Dim builder As New SqlCommandBuilder(adap)
Dim dt As New DataTable
'Dim InventoryDetailsBindingSource As New BindingSource
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
DataGridView1.AllowUserToAddRows = True
DataGridView1.AllowUserToDeleteRows = True
DataGridView1.[ReadOnly] = False
adap.InsertCommand = builder.GetInsertCommand()
' adap.UpdateCommand = builder.GetUpdateCommand()
adap.UpdateCommand = builder.GetUpdateCommand
adap.Fill(dt)
InventoryDetailsBindingSource.DataSource = dt
DataGridView1.DataSource = InventoryDetailsBindingSource
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
If TextBox1.TextLength > 0 Then
InventoryDetailsBindingSource.Filter = String.Format("First_Name Like '%{0}%'", TextBox1.Text)
Else
InventoryDetailsBindingSource.Filter = String.Empty
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
adap.Update(dt)
MessageBox.Show("Saved successfully")
Catch ex As Exception
MessageBox.Show("Error updating database")
End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
adap.Update(dt)
DataGridView1.[ReadOnly] = True
Button2.Enabled = False
End Sub
End Class
Actually I was incorrect. I did not have a primary key set on my database. I dropped my table - recreated with primary key.