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 ExistingStudent Form
Dim dt As New DataTable
Dim rowIndex As Integer = 0
Private Sub btnBack_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s)
Dim frmMenu As New Menu
frmMenu.Show()
Me.Hide()
End Sub
Private Sub PicUpload_Click (ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles PicUpload.Click
OpenFileDialog1 .InitialDirecto ry = "F:\Ankit\Tames ide College _
HND Year 1\Unit 7_Visual Basic.NET\SIRS_ Use THIS ONE\Photos"
OpenFileDialog1 .ShowDialog()
OpenFileDialog1 .Filter =
"Bitmaps(*.bmp) |*.bmp|JPEG(*.j pg)|*.jpg|GIF(* .gif)|*.gif"
picperson.Image = Image.FromFile( OpenFileDialog1 .FileName)
picperson.SizeM ode = PictureBoxSizeM ode.CenterImage
End Sub
Sub updateTextBoxes ()
txtStudentID.Te xt =
CStr(dt.Rows(ro wIndex)("Person alDetail.Studen tId"))
txtStudentName. Text = CStr(dt.Rows(ro wIndex)("Name") )
txtAddress.Text = CStr(dt.Rows(ro wIndex)("Addres s"))
txtTown.Text = CStr(dt.Rows(ro wIndex)("Town") )
txtCourse.Text = CStr(dt.Rows(ro wIndex)("Course Name"))
txtDoB.Text = CStr(dt.Rows(ro wIndex)("DOB"))
txtSex.Text = CStr(dt.Rows(ro wIndex)("Sex"))
txtTelephone.Te xt = CStr(dt.Rows(ro wIndex)("Teleph one"))
txtContactName. Text = CStr(dt.Rows(ro wIndex)("Contac tName"))
txtContactNo.Te xt = CStr(dt.Rows(ro wIndex)("Contac tNumber"))
picperson.Image =
Image.FromFile( CStr(dt.Rows(ro wIndex)("FilePa th")))
End Sub
Private Sub ExistingStudent Form_Load(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles MyBase.Load
Dim constr As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=C:\Docum ents and Settings\Ankit\ Desktop\Tamesid e College _ HND
Year 1\Unit 7_Visual Basic.NET\SIRS_ Use THIS ONE\Student
Database\Studen ts.mdb"
Dim SqlStr As String = "SELECT PersonalDetail. *, Course.*,
Picture.* FROM (PersonalDetail INNER JOIN Picture ON
PersonalDetail. StudentId = Picture.Student Id) INNER JOIN Course ON
PersonalDetail. StudentId = Course.StudentI d"
Dim dataAdapter As New OleDb.OleDbData Adapter(SqlStr, constr)
dataAdapter.Fil l(dt)
dataAdapter.Dis pose()
updateTextBoxes ()
End Sub
Private Sub btnPrevious_Cli ck(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles btnPrevious.Cli ck
If (rowIndex 0) Then
rowIndex = rowIndex - 1
updateTextBoxes ()
End If
End Sub
Private Sub btnNext_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) 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.EventArg s) 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) ("personalDetai l.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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnSave.Click
End Sub
End Class
""""""""""""""" """"""""""""""" """"""""""""""" """"""""""""""" """"""""""""""" """"""""""""""" """"""""""""""" """"""""""""""" """"""""""""""" """"""""""""""" """""""""
Thanks.
Do reply either here or send me e mail me at
an************* ***@yahoo.com / an***********@g mail.com
Cheers.