I am creating a bank customer's details application. The information is stored on a Microsoft Access file and I was able to make the information appear on my VB application through text boxes and a DataGridView but I am not able to save,edit or delete records. Does anybody have any ideas. Below is my code. -
-
Public Class frmCustomerDetails
-
-
Dim objDS As New DataSet
-
Dim rowIndex As Integer = 0
-
Dim objConn As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & "Data Source=F:\Database-driven banking application\Database-driven banking application\bin\CustomerDetails.mdb"
-
-
Dim objSqlStr As String = "SELECT * FROM CustomerDetails"
-
Dim objDA As New OleDb.OleDbDataAdapter(objSqlStr, objConn)
-
-
-
-
-
Sub UpdateTextBoxes()
-
-
txtCustomerID.Text = CStr(objDS.Tables(0).Rows(rowIndex)("CustomerID"))
-
txtFirstName.Text = CStr(objDS.Tables(0).Rows(rowIndex)("FirstName"))
-
txtLastName.Text = CStr(objDS.Tables(0).Rows(rowIndex)("LastName"))
-
txtAddress.Text = CStr(objDS.Tables(0).Rows(rowIndex)("Address"))
-
txtHomeNumber.Text = CStr(objDS.Tables(0).Rows(rowIndex)("HomeNumber"))
-
txtMobileNumber.Text = CStr(objDS.Tables(0).Rows(rowIndex)("MobileNumber"))
-
txtNotes.Text = CStr(objDS.Tables(0).Rows(rowIndex)("Notes"))
-
-
End Sub
-
-
-
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
-
-
If rowIndex < objDS.Tables(0).Rows.Count - 1 Then
-
rowIndex = rowIndex + 1
-
UpdateTextBoxes()
-
-
End If
-
-
End Sub
-
-
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
-
-
If rowIndex > 0 Then
-
rowIndex = rowIndex - 1
-
UpdateTextBoxes()
-
End If
-
-
End Sub
-
-
Private Sub txtFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFind.Click
-
-
Dim rowcount As Integer
-
rowcount = objDS.Tables(0).Rows.Count - 1
-
-
Dim ownerFound As Boolean = False
-
Dim lastname As String = InputBox("Enter a last name Please!", "Search")
-
For i As Integer = 0 To objDS.Tables(0).Rows.Count - 1
-
If CStr(objDS.Tables(0).Rows(i)("LastName")) = lastname Then
-
ownerFound = True
-
rowIndex = i
-
UpdateTextBoxes()
-
-
End If
-
Next
-
-
End Sub
-
-
Private Sub frmCustomerDetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
-
objDA.Fill(objDS)
-
objDA.Dispose()
-
-
DataGridView1.DataSource = objDS.Tables(0)
-
UpdateTextBoxes()
-
-
End Sub
-
-
-
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
-
-
Dim objRow As DataRow
-
Dim FirstName As String
-
Dim LastName As String
-
-
FirstName = txtFirstName.Text
-
LastName = txtLastName.Text
-
-
'Create a new DataRow object for this table
-
objRow = objDS.Tables("CustomerDetails").NewRow
-
'Edit Each Field value
-
objRow.Item("FirstName") = FirstName
-
objRow.Item("LastName") = LastName
-
-
-
-
'Officially add the DataRow to our table
-
objDS.Tables("CustomerDetails").Rows.Add(objRow)
-
-
objDA.Update(objDS, "CustomerDetails")
-
-
-
End Sub
-
-
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
-
-
rowIndex = 0
-
UpdateTextBoxes()
-
-
End Sub
-
-
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
-
-
-
-
-
-
-
End Sub
-
-
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
-
-
If Not DataGridView1.CurrentRow.IsNewRow Then
-
DataGridView1.Rows.Remove(DataGridView1.CurrentRow)
-
End If
-
-
End Sub
-
End Class
-
-
15 1948
There are a number of problems with this code. Suggest debugging and trying to solve some first. Thanks.
It actually only throws up one error in run time and that is line 84. The error is 'Object reference not set to an instance of an object.'
Problem is due to ur dataset object objDS
At time of Add, Delete or Edit event u r dataset is null. so u must store dataset in session and on each event take it from session and then do operation u want.
Problem is due to ur dataset object objDS
At time of Add, Delete or Edit event u r dataset is null. so u must store dataset in session and on each event take it from session and then do operation u want.
Hi thanks,
How would I do that if u dont mind telling me??
Plater 7,872
Recognized Expert Expert
Hi thanks,
How would I do that if u dont mind telling me??
I see when you reqest the table from your dataset that you give the table a name. However, no where do I see you assigning that name to the table you have. My guess would be that since there is no table with that name in the dataset, it throws that error.
As for checking for null, unsure how in VB, but I think it's like -
if objDS.Tables("CustomerDetails") is null
-
'something to do if dataset is null
-
end if
-
Excellent I've got it to sabe in run time but does'nt stayed saved in the database. It adds to the DataGridView in run time but when i start the application again the new records are deleted.
When i do add a new record in run time a marker comes up in the datagrid saying ' Update requires a valid InsertCommand when passed DataRow collection with new rows.'
Anyone have any ideas??
Do you have an insert command in your dataadapter? If so what is it?
I don't think so. All my code is above. Im not familar with insert command!
Plater 7,872
Recognized Expert Expert
I don't think so. All my code is above. Im not familar with insert command!
Well that would be why it is telling you it doesn't have the insert command, because it doesn't!
You will need to create an SQL INSERT statement for your DataAdapter
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Henok Girma |
last post by:
Hello Gurus,
I want to save the state of an unbound DataGridView on my Windows Form
application to an XML file so i can later load it back..
Basically, on my form I have a DataGridView, it's got some
DataGridViewTextBoxCell, DataGridViewComboBoxCell etc, i want to export all
that to XML..
Any help is greatly appreciated.
|
by: Rich |
last post by:
Hello,
I need to pull data from 2 tables that reside on the same sql server but 2
different databases. In Query Analyzer I can say this
select t1.*, t2.* from tbl1 t1 join database2.dbo.tbl1 t2 on t1.RecordID =
t2.RecordID
The .Net sql command object does not appear to support this kind of syntax.
I need to populate one datagridview with the data from DB1.tbl1 and
|
by: Rich |
last post by:
Hello,
I am populating a datagridview from a datatable and filtering the number of
rows with a dataview object. Is there a way to retrieve the rows displayed
by the datagridview into a separate datatable without having to loop through
each column in the datagridview? Or is there a way to retrieve the rows from
the original datatable filtered by the dataview into a separate table? I
only want to copy the rows from the main table that...
|
by: bob |
last post by:
Can anyone tell me the best way to update a dataset while it is being
edited/viewed in the DataGridView control? Is this something that
should be inserted into one of the grid's events? or should you update
after closing the grid/form, etc.?
Also, can you tell me the best book to buy that fully explains the
DataGridView control?
Thanks.
|
by: Mitchell S. Honnert |
last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the
DataGridView? If not, is there an easy way to duplicate the
DataGridTableStyle's functionality for the DataGridView?
Here's the background for my question...
Before I switched my application over to the Fx 2.0, I used a DataGrid to
display my data. I would store different DataGridTableStyles (each one with
a custom set of columns) in the DataGrid.TableStyles property...
| |
by: =?Utf-8?B?TG9zdEluTUQ=?= |
last post by:
Hi All :)
I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView.
True DBGrid has a MultipleLines property that controls whether individual
records span multiple lines. Is there an equivalent property for the
DataGridView? I have searched, but have not found one.
I would like the user to be able to see all the columns of the table on one
screen - thus eliminating the need to use the horizontal scroll bar to view...
|
by: jeastman - Hotmail |
last post by:
Hello world
Excuse, not to be written English and it helps me with a translator.
I am new programming in C#.
I made a control inheriting the DataGridView to be able to add controls done
by my.
|
by: Andrus |
last post by:
I have DataGridView in virtual mode containing 3500 rows.
In code below, assigning to RowCount value to 3500 takes 8 seconds.
CPU usage goes high at this time.
Stepping by F11 into user code shows few celltemplate property getters and
combobox/datecombo constructor calls without database access which does not
take a lot of time.
Debug output (below) shows lot of messages Stepping over non-user code.
Running in release mode from...
|
by: priyamtheone |
last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have:
1) Initially all the cells of the dtp column should be blank unless they are filled by the user.
2) As soon as the user enters a cell, the dtp control should appear as the editing control of that cell. If there's a value in the cell beforehand, that value is set as the value of the dtp editing control...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |