Click here to Skip to main content
15,914,395 members
Home / Discussions / Database
   

Database

 
GeneralRe: Getting data related to what has been selected randomly from a database Pin
LucBite13-Jul-09 4:16
LucBite13-Jul-09 4:16 
GeneralRe: Getting data related to what has been selected randomly from a database Pin
Vimalsoft(Pty) Ltd13-Jul-09 4:32
professionalVimalsoft(Pty) Ltd13-Jul-09 4:32 
GeneralRe: Getting data related to what has been selected randomly from a database Pin
Blue_Boy13-Jul-09 4:33
Blue_Boy13-Jul-09 4:33 
GeneralRe: Getting data related to what has been selected randomly from a database Pin
DoctorMick13-Jul-09 6:13
DoctorMick13-Jul-09 6:13 
GeneralRe: Getting data related to what has been selected randomly from a database Pin
Jerry Hammond13-Jul-09 10:34
Jerry Hammond13-Jul-09 10:34 
QuestionSplitter container Pin
Isaac Gordon13-Jul-09 0:01
Isaac Gordon13-Jul-09 0:01 
AnswerRe: Splitter container Pin
Muhammad Mazhar13-Jul-09 0:43
Muhammad Mazhar13-Jul-09 0:43 
QuestionCan't save new records to the dataset - I'm practising with the binary formatter Pin
BluesEnd12-Jul-09 17:43
BluesEnd12-Jul-09 17:43 
I’m practicing a database and I have a 3-column table. I’m using binary formatting to save/open the file. I can’t see what is wrong with my code –
I can display records in the datagrid view ok when I press the save button
I can also save the records into the dataset ok when the save/close button is pressed.
When I reopen the programme and press the reload button to reload the dataset, additional records will not be displayed nor saved though original records will be showing in the datagrid.
When I reopen the programme and DO NOT press the reload button, I can enter new records and they will be saved because this is basically overwrites the original dataset.
Ideally, I want to be able to open the dataset and then be able to add new records to the dataset/datatable.
Any help and advice on how to correct this?
Thanks,
Steve

Here is my code:

Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary

Public Class Frm_DataEntry
Dim ThePoint As New Point(540, 150)
Public TheRecord As DataRow
Dim ii As Integer

Private Sub Frm_DataEntry_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Location = ThePoint
End Sub

Private Sub Tbx01_FirstName_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tbx01_FirstName.Enter
Tbx01_FirstName.Clear()
Tbx02_LastName.Clear()
Tbx03_Phone.Clear()
End Sub

Private Sub Btn01_Save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn01_Save.Click
TheRecord = Frm_Mainform.dt_Table.NewRow


TheRecord(Frm_Mainform.dt_Col02_FirstName) = Tbx01_FirstName.Text
TheRecord(Frm_Mainform.dt_Col03_LastName) = Tbx02_LastName.Text

Frm_Mainform.dt_Table.Rows.Add(TheRecord)
Frm01_WithDGV.DGV01.DataSource = Frm_Mainform.ds_Dataset
Frm01_WithDGV.DGV01.DataMember = Frm_Mainform.dt_Table.ToString

Frm01_WithDGV.DGV01_BS_Col01_PKey.DataPropertyName = Frm_Mainform.dt_Col01_PKey.ToString
Frm01_WithDGV.DGV01_BS_Col02_FirstName.DataPropertyName = Frm_Mainform.dt_Col02_FirstName.ToString
Frm01_WithDGV.DGV01_BS_Col03_LastName.DataPropertyName = Frm_Mainform.dt_Col03_LastName.ToString

Dim ii As Integer
ii = Frm_Mainform.dt_Table.Rows.Count
MessageBox.Show(ii)

End Sub

Private Sub Btn02_SaveAndClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn02_SaveAndClose.Click
Dim Filename As String = "PermitToWork.pmt"
Dim fStream As FileStream

Frm01_WithDGV.DGV01.DataSource = Frm_Mainform.ds_Dataset
Frm01_WithDGV.DGV01.DataMember = Frm_Mainform.dt_Table.ToString

Frm01_WithDGV.DGV01_BS_Col01_PKey.Width = 90
Frm01_WithDGV.DGV01_BS_Col02_FirstName.Width = 125
Frm01_WithDGV.DGV01_BS_Col03_LastName.Width = 125
Frm01_WithDGV.DGV01_BS_Col04_Date.Width = 125
Frm01_WithDGV.DGV01_BS_Col01_PKey.DataPropertyName = Frm_Mainform.dt_Col01_PKey.ToString
Frm01_WithDGV.DGV01_BS_Col02_FirstName.DataPropertyName = Frm_Mainform.dt_Col02_FirstName.ToString
Frm01_WithDGV.DGV01_BS_Col03_LastName.DataPropertyName = Frm_Mainform.dt_Col03_LastName.ToString

If File.Exists(Filename) Then
Try
fStream = New FileStream(Filename, FileMode.Create)
Dim binFormat As New BinaryFormatter
binFormat.Serialize(fStream, Frm_Mainform.ds_Dataset)
Catch anex As ArgumentNullException
MsgBox("The inventory could not be accessed")
Catch ex As SerializationException
MsgBox("The application failed to retrieve the inventory")
Finally
fStream.Close()
End Try
Else
Return
End If

Frm_Mainform.Close()
End Sub

Private Sub Btn03_Reload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn03_Reload.Click
Dim Filename As String = "PermitToWork.pmt"
Dim fStream As FileStream

If File.Exists(Filename) Then
Try
fStream = New FileStream(Filename, FileMode.OpenOrCreate, FileAccess.ReadWrite)
Dim binFormat As New BinaryFormatter
Frm_Mainform.ds_Dataset = binFormat.Deserialize(fStream)

Frm01_WithDGV.DGV01.DataSource = Frm_Mainform.ds_Dataset
Frm01_WithDGV.DGV01.DataMember = Frm_Mainform.dt_Table.ToString

Frm01_WithDGV.DGV01_BS_Col01_PKey.Width = 90
Frm01_WithDGV.DGV01_BS_Col02_FirstName.Width = 125
Frm01_WithDGV.DGV01_BS_Col03_LastName.Width = 125
Frm01_WithDGV.DGV01_BS_Col04_Date.Width = 125
Frm01_WithDGV.DGV01_BS_Col01_PKey.DataPropertyName = Frm_Mainform.dt_Col01_PKey.ToString
Frm01_WithDGV.DGV01_BS_Col02_FirstName.DataPropertyName = Frm_Mainform.dt_Col02_FirstName.ToString
Frm01_WithDGV.DGV01_BS_Col03_LastName.DataPropertyName = Frm_Mainform.dt_Col03_LastName.ToString

Catch anex As ArgumentNullException
MsgBox("The inventory could not be accessed")
Catch ex As SerializationException
MsgBox("The application failed to retrieve the inventory")
Finally
fStream.Close()
End Try
Else
Return
End If

Frm01_WithDGV.DGV01_BS_Col01_PKey.Width = 90
Frm01_WithDGV.DGV01_BS_Col02_FirstName.Width = 125
Frm01_WithDGV.DGV01_BS_Col03_LastName.Width = 125
Frm01_WithDGV.DGV01_BS_Col04_Date.Width = 125

Dim ii As Integer
ii = Frm01_WithDGV.DGV01.Rows.Count
MessageBox.Show(ii)

End Sub

End Class

Thanks for your help and advice!
Steve

QuestionReporting Services Pin
devvvy12-Jul-09 16:57
devvvy12-Jul-09 16:57 
Questionsql execution audit - tools? Pin
devvvy12-Jul-09 15:02
devvvy12-Jul-09 15:02 
AnswerRe: sql execution audit - tools? Pin
Niladri_Biswas13-Jul-09 16:17
Niladri_Biswas13-Jul-09 16:17 
QuestionSQL 2008 SQLPUBWIZ Command Line Failure Pin
Member 400112012-Jul-09 12:46
Member 400112012-Jul-09 12:46 
QuestionFROM SQL SERVER 2005 DOWNLOAD FILES FROM PSFTP Pin
ps_prakash0212-Jul-09 6:15
ps_prakash0212-Jul-09 6:15 
AnswerRe: FROM SQL SERVER 2005 DOWNLOAD FILES FROM PSFTP Pin
Jan Wild21-Dec-09 4:30
Jan Wild21-Dec-09 4:30 
QuestionHow do i retrieve data from an MS sql database hosted on a web server Pin
ChiSmile11-Jul-09 4:16
ChiSmile11-Jul-09 4:16 
AnswerRe: How do i retrieve data from an MS sql database hosted on a web server Pin
ChiSmile12-Jul-09 4:39
ChiSmile12-Jul-09 4:39 
AnswerRe: How do i retrieve data from an MS sql database hosted on a web server Pin
Mycroft Holmes12-Jul-09 19:38
professionalMycroft Holmes12-Jul-09 19:38 
GeneralRe: How do i retrieve data from an MS sql database hosted on a web server Pin
ChiSmile13-Jul-09 9:28
ChiSmile13-Jul-09 9:28 
AnswerRe: How do i retrieve data from an MS sql database hosted on a web server Pin
Vimalsoft(Pty) Ltd13-Jul-09 4:11
professionalVimalsoft(Pty) Ltd13-Jul-09 4:11 
GeneralRe: How do i retrieve data from an MS sql database hosted on a web server Pin
ChiSmile13-Jul-09 9:17
ChiSmile13-Jul-09 9:17 
GeneralRe: How do i retrieve data from an MS sql database hosted on a web server Pin
Vimalsoft(Pty) Ltd13-Jul-09 20:06
professionalVimalsoft(Pty) Ltd13-Jul-09 20:06 
GeneralRe: How do i retrieve data from an MS sql database hosted on a web server Pin
ChiSmile14-Jul-09 13:37
ChiSmile14-Jul-09 13:37 
GeneralRe: How do i retrieve data from an MS sql database hosted on a web server Pin
Vimalsoft(Pty) Ltd14-Jul-09 20:29
professionalVimalsoft(Pty) Ltd14-Jul-09 20:29 
QuestionHiring Home Based Workers (3016) Pin
maliksp11-Jul-09 1:35
maliksp11-Jul-09 1:35 
AnswerAdvertisment Pin
Eddy Vluggen11-Jul-09 3:53
professionalEddy Vluggen11-Jul-09 3:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.