473,396 Members | 2,029 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,396 software developers and data experts.

Deleting rows from a table

I have the following code which retreives data from Excel spreadsheet.
How do I exclude or delete records from the table that have blank first column, I do not need to write the records back.

Thanks
Peter

Dim excelConnection As System.Data.OleDb.OleDbConnection
Dim dbg As DataGrid
Dim DtSet As New System.Data.DataSet

Try
'
' Fetch Data from Excel
'
Dim cmd As System.Data.OleDb.OleDbDataAdapter

excelConnection = New System.Data.OleDb.OleDbConnection("provider=Micros oft.Jet.OLEDB.4.0; " & _
"data source='" & pathExcelFile & " '; " & "Extended Properties=Excel 8.0;")
'
' Select the data from sheet of the workbook.
'
cmd = New System.Data.OleDb.OleDbDataAdapter("select * from [" & workSheetName & "$]", excelConnection)
cmd.TableMappings.Add("Table", "Data")
cmd.Fill(DtSet)

Catch ex As Exception
excelConnection.Close()
Finally
excelConnection.Close()
End Try

Return DtSet.Tables(0)

Nov 23 '05 #1
4 2679
One more thing
the first column in the spreadsheet is a Date and Time
"Peter" <pc*****@online.nospam> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
I have the following code which retreives data from Excel spreadsheet.
How do I exclude or delete records from the table that have blank first column, I do not need to write the records back.

Thanks
Peter

Dim excelConnection As System.Data.OleDb.OleDbConnection
Dim dbg As DataGrid
Dim DtSet As New System.Data.DataSet

Try
'
' Fetch Data from Excel
'
Dim cmd As System.Data.OleDb.OleDbDataAdapter

excelConnection = New System.Data.OleDb.OleDbConnection("provider=Micros oft.Jet.OLEDB.4.0; " & _
"data source='" & pathExcelFile & " '; " & "Extended Properties=Excel 8.0;")
'
' Select the data from sheet of the workbook.
'
cmd = New System.Data.OleDb.OleDbDataAdapter("select * from [" & workSheetName & "$]", excelConnection)
cmd.TableMappings.Add("Table", "Data")
cmd.Fill(DtSet)

Catch ex As Exception
excelConnection.Close()
Finally
excelConnection.Close()
End Try

Return DtSet.Tables(0)
Nov 23 '05 #2
Hi

I think you can use the RowFilter, first select all the records, and then
use the RowFilter to filter the ones which is not NULL in a DataView, and
the DataView is the result.
You may have a try.

Dim excelConnection As System.Data.OleDb.OleDbConnection
Dim dbg As DataGrid
Dim DtSet As New System.Data.DataSet
Dim pathExcelFile As String = "c:\temp\TestBook.xls"
Dim workSheetName As String = "Sheet1"
Try
'
' Fetch Data from Excel
'
Dim cmd As System.Data.OleDb.OleDbDataAdapter
excelConnection = New
System.Data.OleDb.OleDbConnection("provider=Micros oft.Jet.OLEDB.4.0; " & _
"data source='" & pathExcelFile & " '; " &
"Extended Properties=Excel 8.0;")
'
' Select the data from sheet of the workbook.
'
cmd = New System.Data.OleDb.OleDbDataAdapter("select * from ["
& workSheetName & "$]", excelConnection)
cmd.TableMappings.Add("Table", "Data")
cmd.Fill(DtSet)
Catch ex As Exception
excelConnection.Close()
Finally
excelConnection.Close()
End Try
Dim dv As DataView
dv = New DataView
With dv
.Table = DtSet.Tables(0)
.RowFilter = DtSet.Tables(0).Columns(0).ColumnName & " Is NOT
Null"
End With
Me.DataGrid1.DataSource = dv

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 23 '05 #3

""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
news:18**************@TK2MSFTNGXA02.phx.gbl...
Hi

I think you can use the RowFilter, first select all the records, and then
use the RowFilter to filter the ones which is not NULL in a DataView, and
the DataView is the result.
You may have a try.

Dim excelConnection As System.Data.OleDb.OleDbConnection
Dim dbg As DataGrid
Dim DtSet As New System.Data.DataSet
Dim pathExcelFile As String = "c:\temp\TestBook.xls"
Dim workSheetName As String = "Sheet1"
Try
'
' Fetch Data from Excel
'
Dim cmd As System.Data.OleDb.OleDbDataAdapter
excelConnection = New
System.Data.OleDb.OleDbConnection("provider=Micros oft.Jet.OLEDB.4.0; " & _
"data source='" & pathExcelFile & " '; " &
"Extended Properties=Excel 8.0;")
'
' Select the data from sheet of the workbook.
'
cmd = New System.Data.OleDb.OleDbDataAdapter("select * from ["
& workSheetName & "$]", excelConnection)
cmd.TableMappings.Add("Table", "Data")
cmd.Fill(DtSet)
Catch ex As Exception
excelConnection.Close()
Finally
excelConnection.Close()
End Try
Dim dv As DataView
dv = New DataView
With dv
.Table = DtSet.Tables(0)
.RowFilter = DtSet.Tables(0).Columns(0).ColumnName & " Is NOT
Null"
End With
Me.DataGrid1.DataSource = dv

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.


Thank you this works
Nov 23 '05 #4
Hi

You are welcomed!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 23 '05 #5

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

Similar topics

1
by: rishi | last post by:
Looking for tips on how to improve performance on deleting records. In our database we do dataloads daily that require us to purge millions of records a day so any improvement in speed would be...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following. I'm trying to delete all the rows in a dataview. There are 200 rows. Everything works fine until I delete half way through and then I'm...
2
by: Zak McGregor | last post by:
Hi all I have a table, for simplicity's sake containing one field, called unid. for example, select unid, oid from table gives me something like this: unid | oid ---------+---------
12
by: bikkaran | last post by:
Hi , I have a table that contains 15lakh records..... I want delete that table....and insert fresh set of record. when I run the command ...db2 "delete from schema.tabname" it hangs...
9
by: Hamed | last post by:
Hello I have a DataGrid that a is bound to a DataTable. Some of the rows in the DataTable should not be deleted. How can I prohibit deleting of some identified rows? The problem could be...
24
by: Frank Swarbrick | last post by:
We have a batch process that inserts large numbers (100,000 - 1,000,000) of records into a database each day. (DL/I database.) We're considering converting it to a DB2 table. Currently we have...
1
by: dmcadams | last post by:
I need help deleting 300 Millions of rows from a table and then reclaim the space in the table after completing the delete process. The database needs to be online and available to the users. There...
4
by: MiziaQ | last post by:
Hey, I'm using the following code to write entries to a data file and then read them in an msflexgrid. I now would like to add code under a delete button to use the table(grid) to delete rows from...
2
by: jodleren | last post by:
Hi! In a system, which collects data and the summarises it, we collect a large amount of data. Now, there seems to be a problem, when we try to delete just 16000 rows (entire table btw) or some...
3
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.