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

[VB.NET] Export information from DBF File

I'm trying to export information from a DBF file. I can get all the data to export, but I'm trying to filter out some information using if then. When I try this, I either get all the information or non of it, depending on is nothing or is not nothing. I tried using tostring, but thing I get system comobject in my export.

here's the code I'm using.

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2.  
  3. Public Class Form1
  4. Dim stufname
  5. Dim stulname
  6. Dim objFSO
  7. Dim strexport
  8. Dim strTest
  9. Dim sturs
  10. Dim cls
  11. Dim strstatus
  12.  
  13.  
  14. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  15.  
  16.  
  17.  
  18. 'Assign Variables
  19. stuconn = CreateObject("ADODB.Connection")
  20. stuconn.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\exports;Extended Properties=DBASE IV;")
  21. objFSO = CreateObject("Scripting.FileSystemObject")
  22. strexport = objFSO.CreateTextFile("c:\Documents and Settings\All Users\desktop\exports\Students.csv")
  23. StuRS = stuconn.Execute("Select * From [students.dbf]")
  24.  
  25.  
  26. stufname = sturs.Fields("FirstName")
  27. stulname = sturs.Fields("LastName")
  28. stuphone = sturs.Fields("Telephone")
  29. strstatus = sturs.Fields("Status")
  30.  
  31.  
  32. strexport.Write("LastName")
  33. strexport.Write(",")
  34. strexport.Write("FirstName")
  35. strexport.Write(",")
  36. strexport.Write("Phone Number")
  37. strexport.Write(",")
  38. strexport.Write("Status")
  39. strexport.Write(vbCrLf)
  40.  
  41.  
  42.  
  43. Do While Not (StuRS.EOF)
  44. 'On Error Resume Next
  45.  
  46. If strstatus = "" Then
  47.  
  48. strexport.Write(stulname)
  49. strexport.Write(",")
  50. strexport.Write(stufname)
  51. strexport.Write(",")
  52. 'strexport.Write(stuphone)
  53. strexport.Write(",")
  54. 'strexport.Write(strstatus)
  55. strexport.Write(vbCrLf)
  56.  
  57. End If
  58.  
  59.  
  60.  
  61. sturs.MoveNext()
  62.  
  63.  
  64. Loop
  65.  
  66. MsgBox("Export Complete")
  67.  
  68. stuconn.close()
  69. strexport.Close()
  70.  
  71. End Sub
  72.  
  73. End Class
Any suggestions. I can email you the dbf if needed.
Oct 14 '08 #1
4 3033
Curtis Rutland
3,256 Expert 2GB
allenflame,
Welcome to Bytes.com!

Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

Also, please use more descriptive titles. Try to include the language as well as the platform (Web/Desktop/Console). Titles make it easier for experts to find a thread that they can help with.


MODERATOR
Oct 14 '08 #2
Frinavale
9,735 Expert Mod 8TB
Are you getting any error messages?

What are the following variable types??
Expand|Select|Wrap|Line Numbers
  1. Dim stufname
  2. Dim stulname
  3. Dim objFSO
  4. Dim strexport
  5. Dim strTest
  6. Dim sturs
  7. Dim cls
  8. Dim strstatus
  9.  
Oct 14 '08 #3
These are fields in the students.dbf file. I tried going in an setting these to strings
Dim stufname - first name
Dim stulname - last name
Dim strstatus - should be blank, a N or an I
dim stuphone - phone number with just numbers

These I used for exporting, found the code online
Dim objFSO
Dim strexport
Dim strTest
Dim sturs

I tried converting strstatus and stuphone to strings, but I get

System.Runtime.InteropServices.COMException was unhandled
ErrorCode=-2147352571
Message="Type mismatch. (Exception from HRESULT: 0x80020005 )
Oct 14 '08 #4
Frinavale
9,735 Expert Mod 8TB
You should really consider the Data Types that your variables will use....

Also, consider using a DataAdpater and a DataSet to retrieve the data


EG (this code will most likely Not Work. It's meant to give you and idea of how to use the DataSet and DataAdpater. Give it a try and see what happens)


Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2.  
  3. Public Class Form1
  4. Dim stufname As String
  5. Dim stulname As String
  6. Dim objFSO
  7. Dim strexport
  8. Dim strTest
  9. Dim sturs
  10. Dim cls
  11. Dim strstatus
  12.  
  13.  
  14. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  15.  
  16.  
  17.  
  18. 'Assign Variables
  19. Dim stuconn As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\exports;Extended Properties=DBASE IV;")
  20. stuconn .Open()
  21.  
  22. Dim daSql As New DataAdapter
  23. Dim dsData As New DataSet 
  24.  
  25. Dim sqlStatement = "select * from material;"
  26. daSQL.SelectCommand = New OleDb.OleDbCommand(sqlStatement , stuconn)
  27.  
  28. daSQL.Fill(dsData, "tblMaterial")
  29.  
  30. Dim tblMaterial As DataTable = daSQL.Tables("tblMaterial")
  31.  
  32. For Each sturs As DataRow in tblMaterial.Rows
  33.  
  34. stufname = sturs.Item("FirstName")
  35. stulname = sturs.Item("LastName")
  36. stuphone = sturs.Item("Telephone")
  37. strstatus = sturs.Item("Status")
  38.  
  39.  
  40. strexport.Write("LastName")
  41. strexport.Write(",")
  42. strexport.Write("FirstName")
  43. strexport.Write(",")
  44. strexport.Write("Phone Number")
  45. strexport.Write(",")
  46. strexport.Write("Status")
  47. strexport.Write(vbCrLf)
  48.  
  49. Next
  50.  
  51. MsgBox("Export Complete")
  52.  
  53. stuconn.close()
  54. strexport.Close()
  55.  
  56. End Sub
  57.  
  58. End Class
Oct 14 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Brian Hanson | last post by:
Hi, I am trying to programmatically print a pdf file via an asp.net application. I have seen other postings that mention the following code used or something similar to it in a vb.net app. ...
1
by: Thomas Holmgren | last post by:
Hi all I've tried to get my hands on the End User License Agreement for MS Visual C# .NET 2003 STANDARD edition, sofar without luck. Does anybody know where I can find the license agreement...
0
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, TlbExp.exe and Regasm.exe tools aid us in exporting assembly information to a type library so that non .Net Applications or unmanaged code use this type library information to call...
4
by: Jae | last post by:
I'm writing a web application that exports and imports excel files. The application gets a list of users and their info and displays it in a datagrid .The user then selects to save the file as a...
1
by: pareptrc | last post by:
Dear all, I want to write a pdf file from crystal report in my web application. Here is my proc: Private Sub CreatePDFReport(ByVal KeyReference As String) Dim objReport As New...
6
by: JimmyKoolPantz | last post by:
I have been given the task of converting a program from VFP (visual foxpro) to Visual Basic.net. My question is "Is it possible to generate a DBF file Dynamically(at runtime) using Visual...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
5
by: bhodgins | last post by:
Hi, I am new on here, and had a newbie question that I am stumped with. I am not new to access, but am new to VB. I am trying to export BLOBs from a field called photo to external jpeg files. 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?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.