I have written a small program that only has one table. When the program loads I select the csv file to load into the table. I then truncate the table and bulk insert from the csv file into the table to load all the records.
I have a second dialog form that i load from a button. On this form i create reports with a .net report and report viewer. The problem is that the report viewer always show the data that was in the table before the insert of the new csv. Its like it is loading the report info from a snapshot of the previous data.
Please Help

Data Not update
wyl86
here is the code:
Main form:
Imports
system.io, System.dataPublic
Class Form1 Dim value As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loadshowfiles()
End Sub
Private Sub GO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetPnl.Clickcreatetable()
getallparts()
End Sub Sub createtable()value =
String.Concat("J", ((cboPnlFiles.SelectedItem.ToString).Remove((cboPnlFiles.SelectedItem.ToString).Length - 4))) TryCreateTableCommand.CommandText =
"TRUNCATE Table PARTS"CreateTableCommand.Connection.Open()
CreateTableCommand.ExecuteNonQuery()
CreateTableCommand.Connection.Close()
Catch ex As ExceptionCreateTableCommand.Connection.Close()
End Try 'CreateTableCommand.CommandText = "CREATE TABLE PARTS (PartDescription varchar(24), FinishedLength Numeric, FinishedWidth Numeric, CutSizeLength numeric, CutSizeWidth numeric,CutSizeThickness numeric, Quantity int, Grain int, BandingCode int, MaterialDescription varchar(24), jobshortname varchar(8), joblongname varchar(24), MaterialNumber varChar(12), WorLGrain char, AdjectiveDescription varchar(5), RoomandCabinet varchar(9), SpecialOpers varchar(24), FirstLengthName varchar(24), FirstLengthMaterial varchar(24), FirstLengthThickness varchar(24), FirstLengthEdgeProgram Varchar(24), SecondLengthName varchar(24), SecondLengthMaterial varchar(24), SecondLengthThickness varchar(24), SecondLengthEdgeProgram Varchar(24), FirstWidthName varchar(24), FirstWidthMaterial varchar(24), FirstWidthThickness varchar(24), FirstWidthEdgeProgram Varchar(24), SecondWidthName varchar(24), SecondWidthMaterial varchar(24), SecondWidthThickness varchar(24), SecondWidthEdgeProgram Varchar(24), UniqueId varchar(24))" 'CreateTableCommand.Connection.Open() 'CreateTableCommand.ExecuteNonQuery() 'CreateTableCommand.Connection.Close() 'CreateTableCommand.CommandText = "CREATE INDEX PnlIndex ON PARTS (UniqueId)" 'CreateTableCommand.Connection.Open() 'CreateTableCommand.ExecuteNonQuery() 'CreateTableCommand.Connection.Close()CreateTableCommand.CommandText =
"BULK INSERT PARTS FROM '\\server-01\cabnetware\jobs\" & cboPnlFiles.SelectedItem.ToString & "' WITH (FIRSTROW = 2, FIELDTERMINATOR = ',', ROWTERMINATOR = '\n')"CreateTableCommand.Connection.Open()
CreateTableCommand.ExecuteNonQuery()
CreateTableCommand.Connection.Close()
End Sub Sub showfiles() Dim FILE As String Dim FI As FileInfo For Each FILE In Directory.GetFiles("\\server-01\cabnetware\jobs")FI =
New FileInfo(FILE) If FI.Extension = ".PNL" ThencboPnlFiles.Items.Add(FI.Name)
End If Next End Sub Sub getallparts() Dim selectcmd As String = "select * from PARTS" Dim connstring As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Simonetguest\My Documents\Visual Studio 2005\Projects\Parts List Editor\Parts List Editor\partslists.mdf;Integrated Security=True;User Instance=True" Dim PNLconnect As New SqlClient.SqlConnection(connstring) Dim fillcommand As New SqlClient.SqlDataAdapter() Dim aselectcommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(selectcmd, PNLconnect)fillcommand.SelectCommand = aselectcommand
PNLconnect.Open()
Dim data As New DataSetdata.Clear()
fillcommand.Fill(data,
"parts")dataGrid.DataSource = data
PNLconnect.Close()
dataGrid.DataSource = data.Tables(0)
Dim arow As DataRow Dim total As Integer Dim Left As Integer Dim Right As Integer Dim Pair As Integer For Each arow In data.Tables(0).Rowstotal = total + arow.Item(6)
If arow.Item(14) = "Left " ThenLeft = Left + 1
End If If arow.Item(14) = "Right" ThenRight = Right + 1
End If If arow.Item(14) = "Pair " ThenPair = Pair + 1
End If NextlblLefts.Text = Left
lblRights.Text = Right
lblPairs.Text = Pair
lblTotalNumberofParts.Text = total
lblNumberofParts.Text = data.Tables(0).Rows.Count
End Sub Sub search() Dim selectcmd As String = "select * from PARTS Where " If tbxCabinetNumber.Text <> Nothing Then Dim cabinetNumber As String = tbxCabinetNumber.Text.ToString If selectcmd.IndexOfAny("=") > -1 Thenselectcmd = selectcmd &
" And RoomandCabinet='" & cabinetNumber & "'" Elseselectcmd = selectcmd &
" RoomandCabinet='" & cabinetNumber & "'" End If End If If tbxLength.Text <> Nothing Then If selectcmd.IndexOfAny("=") > -1 Thenselectcmd = selectcmd &
" And FinishedLength=" & tbxLength.Text Elseselectcmd = selectcmd &
" FinishedLength=" & tbxLength.Text End If End If If tbxWidth.Text <> Nothing Then If selectcmd.IndexOfAny("=") > -1 Thenselectcmd = selectcmd &
" And FinishedWidth=" & tbxWidth.Text Elseselectcmd = selectcmd &
" FinishedWidth=" & tbxWidth.Text End If End If If rdoSearchDoors.Checked = True Then If selectcmd.IndexOfAny("=") > -1 Thenselectcmd = selectcmd &
" And PartDescription='Door Panel'" Elseselectcmd = selectcmd &
" PartDescription='Door Panel'" End If End If If rdoSearchGables.Checked = True Then If selectcmd.IndexOfAny("=") > -1 Thenselectcmd = selectcmd &
" And PartDescription='Gable'" Elseselectcmd = selectcmd &
" PartDescription='Gable'" End If End If Dim connstring As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Simonetguest\My Documents\Visual Studio 2005\Projects\Parts List Editor\Parts List Editor\partslists.mdf;Integrated Security=True;User Instance=True" Dim PNLconnect As New SqlClient.SqlConnection(connstring) Dim fillcommand As New SqlClient.SqlDataAdapter() Dim aselectcommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(selectcmd, PNLconnect)fillcommand.SelectCommand = aselectcommand
PNLconnect.Open()
Dim data As New DataSetdata.Clear()
Tryfillcommand.Fill(data,
"parts") Catch ex As ExceptionPNLconnect.Close()
MessageBox.Show(
"You Must Load a PNL File to Search First", "You Fucked UP Idiot") Exit Sub End TrydataGrid.DataSource = data
PNLconnect.Close()
dataGrid.DataSource = data.Tables(0)
Dim arow As DataRow Dim total As Integer Dim Left As Integer Dim Right As Integer Dim Pair As Integer For Each arow In data.Tables(0).Rowstotal = total + arow.Item(6)
If arow.Item(14) = "Left " ThenLeft = Left + (1 * arow.Item(6))
End If If arow.Item(14) = "Right" ThenRight = Right + (1 * arow.Item(6))
End If If arow.Item(14) = "Pair " ThenPair = Pair + (1 * arow.Item(6))
End If NextlblLefts.Text = Left
lblRights.Text = Right
lblPairs.Text = Pair
lblTotalNumberofParts.Text = total
lblNumberofParts.Text = data.Tables(0).Rows.Count
End Sub Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Clicksearch()
End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSingleCabinetSearch.Clicksearch()
End Sub Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim printdialog As New Dialog1printdialog.ShowDialog()
printdialog.Dispose()
End SubEnd
ClassSecond Form:
Imports
System.Windows.FormsPublic
Class Dialog1 Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click Me.DialogResult = System.Windows.Forms.DialogResult.OK Me.Close() End Sub Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click Me.DialogResult = System.Windows.Forms.DialogResult.Cancel Me.Close() End Sub Private Sub btnDoors_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAllParts.Click Me.reportviewer.Reset() Me.PARTSTableAdapter.Fill(Me.reportdataset.PARTS) Dim ReportDataSource3 As Microsoft.Reporting.WinForms.ReportDataSource = New Microsoft.Reporting.WinForms.ReportDataSourceReportDataSource3.Name =
"reportdataset_PARTS"ReportDataSource3.Value =
Me.PARTSBindingSource Me.reportviewer.LocalReport.DataSources.Add(ReportDataSource3) Me.reportviewer.LocalReport.ReportEmbeddedResource = "Parts_List_Editor.CompleteList.rdlc" Me.reportviewer.Location = New System.Drawing.Point(199, 12) Me.reportviewer.Name = "reportviewer" Me.reportviewer.Size = New System.Drawing.Size(804, 768) Me.reportviewer.TabIndex = 1 Me.reportviewer.RefreshReport() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoors.Click Me.reportviewer.Reset() Me.DoorsTableAdapter.Fill(reportdataset.Doors) Dim ReportDataSource1 As Microsoft.Reporting.WinForms.ReportDataSource = New Microsoft.Reporting.WinForms.ReportDataSourceReportDataSource1.Name =
"reportdataset_Doors"ReportDataSource1.Value =
Me.DoorsBindingSource Me.reportviewer.LocalReport.DataSources.Add(ReportDataSource1) Me.reportviewer.LocalReport.ReportEmbeddedResource = "Parts_List_Editor.DoorsReport.rdlc" Me.reportviewer.Location = New System.Drawing.Point(199, 12) Me.reportviewer.Name = "reportviewer" Me.reportviewer.Size = New System.Drawing.Size(804, 768) Me.reportviewer.TabIndex = 1 Me.reportviewer.RefreshReport() End Sub Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.reportviewer.Reset() Me.drawerfrontsTableAdapter.Fill(reportdataset.drawerfronts) Dim ReportDataSource2 As Microsoft.Reporting.WinForms.ReportDataSource = New Microsoft.Reporting.WinForms.ReportDataSourceReportDataSource2.Name =
"reportdataset_drawerfronts"ReportDataSource2.Value =
Me.drawerfrontsBindingSource Me.reportviewer.LocalReport.DataSources.Add(ReportDataSource2) Me.reportviewer.LocalReport.ReportEmbeddedResource = "Parts_List_Editor.Drawers Report.rdlc" Me.reportviewer.Location = New System.Drawing.Point(199, 12) Me.reportviewer.Name = "reportviewer" Me.reportviewer.Size = New System.Drawing.Size(804, 768) Me.reportviewer.TabIndex = 1 Me.reportviewer.RefreshReport()
End Sub Private Sub Dialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End SubEnd
ClassHope this helps !!!!!
Tim Walker 1963