473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Save Changes in VB.NET 2005 with Access 2003 --- Not using any Binding Navigator

Hi Guys

I have got 3 tables -[Personal Details, Course, Picture] in Access
Database with Student ID as primary Key in all and all tables are
linked with 1 to 1 relationship.

I have code the everying with manual program to access information of
tables on Windows Form. It is working properly. i can see all the
records properly.

I am not using Data Binding Navigator.

I have created SAVE Button on Form and i want that button to update
data/records in main database. [ If i change student Addess on form
then with SAVE Button click event, i want that to update in database]

Can you tell me how i can do it. i have been trying for so many weeks.

Please do help me.

here is the code of the form which is working properly at displaying
data from DB.

"""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""

Imports System.Data

Public Class ExistingStudentForm
Dim dt As New DataTable
Dim rowIndex As Integer = 0

Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim frmMenu As New Menu

frmMenu.Show()
Me.Hide()

End Sub

Private Sub PicUpload_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles PicUpload.Click
OpenFileDialog1.InitialDirectory = "F:\Ankit\Tameside College _
HND Year 1\Unit 7_Visual Basic.NET\SIRS_Use THIS ONE\Photos"
OpenFileDialog1.ShowDialog()
OpenFileDialog1.Filter =
"Bitmaps(*.bmp)|*.bmp|JPEG(*.jpg)|*.jpg|GIF(*.gif) |*.gif"

picperson.Image = Image.FromFile(OpenFileDialog1.FileName)
picperson.SizeMode = PictureBoxSizeMode.CenterImage

End Sub
Sub updateTextBoxes()
txtStudentID.Text =
CStr(dt.Rows(rowIndex)("PersonalDetail.StudentId") )
txtStudentName.Text = CStr(dt.Rows(rowIndex)("Name"))
txtAddress.Text = CStr(dt.Rows(rowIndex)("Address"))
txtTown.Text = CStr(dt.Rows(rowIndex)("Town"))

txtCourse.Text = CStr(dt.Rows(rowIndex)("CourseName"))
txtDoB.Text = CStr(dt.Rows(rowIndex)("DOB"))
txtSex.Text = CStr(dt.Rows(rowIndex)("Sex"))
txtTelephone.Text = CStr(dt.Rows(rowIndex)("Telephone"))
txtContactName.Text = CStr(dt.Rows(rowIndex)("ContactName"))
txtContactNo.Text = CStr(dt.Rows(rowIndex)("ContactNumber"))
picperson.Image =
Image.FromFile(CStr(dt.Rows(rowIndex)("FilePath")) )

End Sub

Private Sub ExistingStudentForm_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load

Dim constr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Documents and Settings\Ankit\Desktop\Tameside College _ HND
Year 1\Unit 7_Visual Basic.NET\SIRS_Use THIS ONE\Student
Database\Students.mdb"

Dim SqlStr As String = "SELECT PersonalDetail.*, Course.*,
Picture.* FROM (PersonalDetail INNER JOIN Picture ON
PersonalDetail.StudentId = Picture.StudentId) INNER JOIN Course ON
PersonalDetail.StudentId = Course.StudentId"

Dim dataAdapter As New OleDb.OleDbDataAdapter(SqlStr, constr)

dataAdapter.Fill(dt)
dataAdapter.Dispose()
updateTextBoxes()
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 btnNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNext.Click
If (rowIndex < dt.Rows.Count - 1) Then
rowIndex += 1
updateTextBoxes()
End If
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnSearch.Click
Dim studentid As String

Dim studentFound As Boolean = False

studentid = InputBox("Enter Student ID")
For i As Integer = 0 To (dt.Rows.Count - 1)
If CStr(dt.Rows(i)("personalDetail.StudentId") = studentid)
Then
studentFound = True
rowIndex = i
updateTextBoxes()
End If
Next

If (Not studentFound) Then
MsgBox("System Cannot find requested Student Information",
0, "Not in Table")
End If
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click




End Sub
End Class

"""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""" """""""""
Thanks.

Do reply either here or send me e mail me at
an****************@yahoo.com / an***********@gmail.com

Cheers.

Nov 18 '06 #1
1 2894
Ankz,

What is the advantage in your idea from a 1 to 1 relation instead of just
set it in the datarow

Now you need at least 9 datatable accesses to do an update.

Cor

"ankz" <an***********@googlemail.comschreef in bericht
news:11**********************@k70g2000cwa.googlegr oups.com...
Hi Guys

I have got 3 tables -[Personal Details, Course, Picture] in Access
Database with Student ID as primary Key in all and all tables are
linked with 1 to 1 relationship.

I have code the everying with manual program to access information of
tables on Windows Form. It is working properly. i can see all the
records properly.

I am not using Data Binding Navigator.

I have created SAVE Button on Form and i want that button to update
data/records in main database. [ If i change student Addess on form
then with SAVE Button click event, i want that to update in database]

Can you tell me how i can do it. i have been trying for so many weeks.

Please do help me.

here is the code of the form which is working properly at displaying
data from DB.

"""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""

Imports System.Data

Public Class ExistingStudentForm
Dim dt As New DataTable
Dim rowIndex As Integer = 0

Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim frmMenu As New Menu

frmMenu.Show()
Me.Hide()

End Sub

Private Sub PicUpload_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles PicUpload.Click
OpenFileDialog1.InitialDirectory = "F:\Ankit\Tameside College _
HND Year 1\Unit 7_Visual Basic.NET\SIRS_Use THIS ONE\Photos"
OpenFileDialog1.ShowDialog()
OpenFileDialog1.Filter =
"Bitmaps(*.bmp)|*.bmp|JPEG(*.jpg)|*.jpg|GIF(*.gif) |*.gif"

picperson.Image = Image.FromFile(OpenFileDialog1.FileName)
picperson.SizeMode = PictureBoxSizeMode.CenterImage

End Sub
Sub updateTextBoxes()
txtStudentID.Text =
CStr(dt.Rows(rowIndex)("PersonalDetail.StudentId") )
txtStudentName.Text = CStr(dt.Rows(rowIndex)("Name"))
txtAddress.Text = CStr(dt.Rows(rowIndex)("Address"))
txtTown.Text = CStr(dt.Rows(rowIndex)("Town"))

txtCourse.Text = CStr(dt.Rows(rowIndex)("CourseName"))
txtDoB.Text = CStr(dt.Rows(rowIndex)("DOB"))
txtSex.Text = CStr(dt.Rows(rowIndex)("Sex"))
txtTelephone.Text = CStr(dt.Rows(rowIndex)("Telephone"))
txtContactName.Text = CStr(dt.Rows(rowIndex)("ContactName"))
txtContactNo.Text = CStr(dt.Rows(rowIndex)("ContactNumber"))
picperson.Image =
Image.FromFile(CStr(dt.Rows(rowIndex)("FilePath")) )

End Sub

Private Sub ExistingStudentForm_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load

Dim constr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Documents and Settings\Ankit\Desktop\Tameside College _ HND
Year 1\Unit 7_Visual Basic.NET\SIRS_Use THIS ONE\Student
Database\Students.mdb"

Dim SqlStr As String = "SELECT PersonalDetail.*, Course.*,
Picture.* FROM (PersonalDetail INNER JOIN Picture ON
PersonalDetail.StudentId = Picture.StudentId) INNER JOIN Course ON
PersonalDetail.StudentId = Course.StudentId"

Dim dataAdapter As New OleDb.OleDbDataAdapter(SqlStr, constr)

dataAdapter.Fill(dt)
dataAdapter.Dispose()
updateTextBoxes()
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 btnNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNext.Click
If (rowIndex < dt.Rows.Count - 1) Then
rowIndex += 1
updateTextBoxes()
End If
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnSearch.Click
Dim studentid As String

Dim studentFound As Boolean = False

studentid = InputBox("Enter Student ID")
For i As Integer = 0 To (dt.Rows.Count - 1)
If CStr(dt.Rows(i)("personalDetail.StudentId") = studentid)
Then
studentFound = True
rowIndex = i
updateTextBoxes()
End If
Next

If (Not studentFound) Then
MsgBox("System Cannot find requested Student Information",
0, "Not in Table")
End If
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click




End Sub
End Class

"""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""" """""""""
Thanks.

Do reply either here or send me e mail me at
an****************@yahoo.com / an***********@gmail.com

Cheers.

Nov 19 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kevin G. Anderson | last post by:
What: CAUG Meeting - Visual Studio 2005 Tools for Office When: Thursday, April 27, 2006, 6PM Who: Jacob Cynamon, Microsoft Where: The Information Management Group 200 W. Monroe St. Suite...
0
by: vishalsangwan | last post by:
Hi Everybody, I am writing an application using the bindingnavigator and the oledbDataAdapter. I am not able to save the changes to the actual access database. Please help me. The code follows. ...
1
by: vishalsangwan | last post by:
Hi Everybody, I am writing an application using the bindingnavigator and the oledbDataAdapter. I am not able to save the changes to the actual access database. Please help me. The code follows. ...
7
by: bhavin30 | last post by:
Is there a way to obtain user information (using LOGON_USER server variables) when you have set up the security to Anonymous Access? I have tried setting the security to both Anonymous + Window...
2
by: Randy | last post by:
Hi, I'd like to add a new blank record to a form for the user to input data. What I am trying to do is exactly what the + on the binding navigator does, with some additional steps involved. So,...
2
by: Randy | last post by:
Hi, I'm trying to figure out some binding navigator code. If I have the primary field value as selected by the user in a combo box, how can I instruct the binding navigator to move to that...
1
by: Robert Dufour | last post by:
Vs2005, .Net 2.0, vb.Net, Winforms I have a form with a binding source, a binding navigator, a table adapter and a dataset (all using sql 2005 same table, to keep it simple) When the user tries...
2
by: jehugaleahsa | last post by:
Hello: We are running into an issue. Whenever our users save using either the save key or a BindingNavigator, whatever control is in focus won't be updated. Our users are getting confused when...
2
by: =?Utf-8?B?RWR3YXJk?= | last post by:
Hi everybody I'm usuing the walkthrough example in MSDN , I successfully created a SQL database and I can retrieve my data in my application using bound controls and Binding navigator but when I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.