Hello All,
I am getting an error trying to update datagridview1 , what i am trying to do is search for an item (BarCode.text) and then display the results to datagridview1 but i just cannot manage to do it , please help me i have been trying for days :(
here is what i have this code is extremely crappy as i have read lots of tutorials and searches.... - Imports System.Data.OleDb
-
-
-
Public Class ServiceCompletedForm
-
Dim connStr As String
-
Dim conn As New OleDbConnection
-
Dim da As New OleDbDataAdapter
-
Dim ds As DataSet = New DataSet
-
Dim cnString As String
-
Dim sqlQRY As String
-
Dim myCmd As New OleDbCommand
-
Dim myDR As OleDbDataReader
-
Dim strSQL As String
-
-
-
Private Sub ServiceCompletedForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
-
DataGridView1.Columns.Add("BarCode", "Item Barcode")
-
End Sub
-
-
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
-
da.Update(ds, "ServiceCompleted")
-
End Sub
-
-
Private Sub SearchBarcodeDELETE()
-
cnString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=..\data\Northwind.mdb"
-
sqlQRY = "SELECT * FROM ServiceCompleted " 'WHERE BarCode'"
-
conn = New OleDbConnection(cnString)
-
Try
-
conn.Open()
-
da = New OleDbDataAdapter(sqlQRY, conn)
-
'create command builder
-
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(da)
-
'fill dataset
-
da.Fill(ds, "ServiceCompleted")
-
DataGridView1.DataSource = ds
-
DataGridView1.DataMember = "ServiceCompleted"
-
Catch ex As OleDbException
-
MsgBox(ex.ToString)
-
Finally
-
' Close connection
-
conn.Close()
-
End Try
-
End Sub
-
Function IsConnected() As Boolean
-
Try
-
'Checks first if already connected to database,if connected, it will be disconnected.
-
If conn.State = ConnectionState.Open Then conn.Close()
-
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=..\data\Northwind.mdb"
-
conn.Open()
-
IsConnected = True
-
Catch ex As Exception
-
MsgBox(ex.Message)
-
End Try
-
End Function
-
Public Function KeyAscii(ByVal UserKeyArgument As KeyPressEventArgs) As Short
-
KeyAscii = Asc(UserKeyArgument.KeyChar)
-
-
End Function
-
Sub SearchBarcode(ByVal Barcode As String)
-
Try
-
If IsConnected() = True Then
-
'Queries to database
-
-
strSQL = "SELECT * FROM servicecompleted WHERE BarCode = '" + Barcode + "' "
-
-
myCmd.CommandText = strSQL
-
myCmd.Connection = conn
-
da.SelectCommand = myCmd
-
myDR = myCmd.ExecuteReader()
-
-
'Display results to table
-
-
While (myDR.Read())
-
-
DataGridView1.Rows.Add(myDR("BarCode")) ', myDR("Description"), myDR("Location"), myDR("Building_Number"), myDR("Test_Tag_Interval"))
-
-
End While
-
End If
-
Catch ex As Exception
-
MsgBox(ex.Message, , "SearchBarcode")
-
End Try
-
conn.Close()
-
End Sub
-
-
Private Sub txtBarcode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtBarcode.KeyPress
-
If Me.KeyAscii(e) = 13 Then
-
If IsConnected() = True Then Call SearchBarcode(txtBarcode.Text)
-
e.Handled = True
-
End If
-
End Sub
-
-
-
End Class
0 1902 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paul Ballatti |
last post by:
hi,
I am attempting to update two databases simultaneously, from one
ASP.NET Web Application, which is written in C#. One database is
local i.e. on my localhost IIS and this has no problems at...
|
by: PaulB |
last post by:
Hi there,
Allthough I searched for previous posts, I was unable to solve my problem.
I try to link my front-mdb with an Excel file using the next line
DoCmd.TransferSpreadsheet acLink, 8,...
|
by: Azel |
last post by:
Hi,
I am trying to learn ADO.net and I keep running into
problems trying to insert data into my Access Database:
data.mdb.
here is my code:
<code>
// Database Variables
|
by: cvncpu |
last post by:
I have this function:
public string SetUserInfo(string AuthID, DataSet dg2)
{
if (AuthID=="********")
{
Oconn.Open();
da.Update(dg2);
Oconn.Close();
|
by: xaime |
last post by:
Hi all,
I have the code below. This is doing what I want, but always has the
following exception:
Update unable to find TableMapping or Datatable 'mytable'
The code I'm using is:
Try
|
by: Billy Yang |
last post by:
Hello,
I write a small program to build a web service. I fill a dataset with data
from VFP database. After I put a record in the dataset and make the update.
When updating the database I get an...
|
by: r2destini |
last post by:
Hi Friends,
I am new to .Net. So I don't know much.
I am facing a problem in updating database through ADO.Net
I am creating the dataset and there is no problem in the updation and...
|
by: Ronald S. Cook |
last post by:
In my client Windows application, I am receiving a DataSet containing one
DataTable. This comes to my client via the business tier on a different
physical machine (we're using WCF if that...
|
by: jonbartlam |
last post by:
Hi There
I'm not sure what exactly is going wrong here. I'm writing an application that retreives a table from a database (tbl_internalfaults) and updates it. (Actually, just the status column will...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |