473,396 Members | 1,865 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.

Problem using OdbcDataAdapter

Hi all,

I am a newbie at dotnet. Been going through someone else's code and
here's a problem:

I am loading a csv file into the database. When there's more than one
record, it works fine, but when there's only one, it fails.

file is:
usrName usrFirstName usrLastName usrTitle usrDepartment usrCostCode
jdoe1 John Doe GA R&D
1234

and so on.

the code to load:
----------start----------------

Private Function getCSVDataset(ByVal strCSVFileName As String) As
System.Data.DataSet
Dim oOdbcConnection As OdbcConnection
Dim oDataAdapter As OdbcDataAdapter
Dim oCommand As OdbcCommand
Dim oDataset As DataSet

Try
Dim sConnString As String = "Driver={Microsoft Text Driver
(*.txt; *.csv)};DBQ=" &
Replace(System.AppDomain.CurrentDomain.BaseDirecto ry & "Log/", "/",
"\\") & ";Extensions=asc,csv,tab,txt;"
oOdbcConnection = New OdbcConnection(sConnString)
oOdbcConnection.Open()

oCommand = New OdbcCommand
With oCommand
.Connection = oOdbcConnection
.CommandType = CommandType.Text
.CommandText = "SELECT * FROM " & strCSVFileName
End With

oDataAdapter = New OdbcDataAdapter
oDataset = New DataSet
oDataAdapter.SelectCommand = New
OdbcCommand(oCommand.CommandText, oOdbcConnection)
oDataAdapter.Fill(oDataset)
Return oDataset
Catch Ex As Exception
Dim objErrorHandler As New Common.ErrorHandler(Ex)
objErrorHandler = Nothing
Return Nothing
Finally
oOdbcConnection.Close()
oOdbcConnection.Dispose()
oDataAdapter.Dispose()

oOdbcConnection = Nothing
oDataAdapter = Nothing
oCommand = Nothing
End Try
End Function
---------end---------------

The code to read:
----------start--------------
Private Function getUserDetails(ByVal strRawUserDetails As String) As
Boolean

Dim objCommon As BusinessLayer.clsCommon
Dim oDtRawUD As DataSet
Dim oRowUD As DataRow
Dim oDtRawUDRows As DataRow()
Dim oDtRawUDRow As DataRow
Dim objErrorHandler As Common.ErrorHandler
Dim iCounter As Integer = 0
Dim bReturn As Boolean = True

Try
objCommon = New BusinessLayer.clsCommon
objErrorHandler = New Common.ErrorHandler

If oDtRawUD Is Nothing Then
bReturn = False
Else

For Each oRowUD In oDtRawUD.Tables.Item(0).Rows
------------End Snippet----------------

(it goes on )

When I look at the data in the immediate window, it shows this if there
are more than one record in the file (excluding column names)

?oDtRawUD.Tables.Item(0).Rows.Item(0).ItemArray
{Length=11}
(0): "jdoe1"
(1): "John"
(2): "Doe"
(3): "GA"
(4): "R&D"
(5): 1234 {Integer}

When there's only one, this happens:

(0): {System.DBNull}

Why? How? Any ideas?

thanks for any help
Sanna

Jan 25 '07 #1
1 1918
<sb********@vantage.com.auwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
Why? How? Any ideas?
Is there a problem with the schema.ini file...?
http://msdn.microsoft.com/library/de...a_ini_file.asp

Does the problem still happen if you use OleDb rather than ODBC...?
http://www.connectionstrings.com/?carrier=textfile
Jan 25 '07 #2

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

Similar topics

0
by: Yair Cohen | last post by:
Hi i have a strange problem: i use code like this: ODBCConnection cnn = new ODBCConnection("... cnn string ..."); ODBCDataAdapter da = new ODBCDataAdapter("select * from tbl left join tbl2...
0
by: Giulio Santorini | last post by:
Hi, I've got two drop down list controls. When I select a value from the first one I fill the second one. And when I select a value from the second one I would like to fill another control. But...
0
by: Steve Bishop | last post by:
I have a form with a search text box and a grid that displays the results. Within the grid, I have edit command links set up to response.redirect to another page that puts the DataKey value in the...
0
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to...
3
by: jm | last post by:
I do not want to use the datagrid, datalist, etc. I want to retrieve simply the value from the query. I know the sql is returning data, because, if I use a grid, I can populate it. I have...
1
by: TomislaW | last post by:
This is the code: OdbcConnection conn = new OdbcConnection(m_ConnectionString); OdbcDataAdapter adapter = new OdbcDataAdapter(); adapter.SelectCommand = new OdbcCommand("spUser", conn); ...
0
by: Lon | last post by:
My csv file has rows like this: "col1","col2","col3","col4","col5" "04/04/2005 01:05:07.576","0","0","0","0" And I am using this code to read the file: Dim Conn As OdbcConnection Dim dt As...
3
by: Rob Dob | last post by:
SQLDataAdapter. ODBCDataAdapter etc. Have they disappeared from .Net 2.0 Webforms? can somone please elaborate as I cannot seem to find support for these..
0
by: roundcrisis | last post by:
hiL i have teh following code: string query = "select * FROM users"; OdbcCommand command = new OdbcCommand(query, conn); OdbcDataAdapter da = new OdbcDataAdapter(); da.SelectCommand = command;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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,...

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.