Getting double records from .csv files

G

Guest

Hi,
I am getting some data from a .csv file through an aspx page. The total no
of records are 744 while i'm getting 1500. I couldn't really figure it out.
I'll write the code below.

Code:
Dim ExcelConnection As New OleDbConnection
Dim ExcelCommand As New OleDbCommand
Dim ExcelAdapter As New OleDbDataAdapter
Dim ExcelDataset As New DataSet
ExcelConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathname +
";Extended Properties=Text;")
ExcelConnection.Open()
ExcelCommand = New OleDbCommand("SELECT * FROM " + filename,
ExcelConnection)
Dim myread As OleDbDataReader
ExcelAdapter = New OleDbDataAdapter(ExcelCommand)
myread = ExcelCommand.ExecuteReader

'If myread.HasRows Then
Dim sqlConn As SqlConnection
sqlConn = New SqlConnection("Server=.;database=Nissan; User Id=sa;
Password=testing")
Dim sqlcmd As New SqlCommand
sqlConn.Open()

While myread.Read

'sqlcmd.CommandText = "Insert imported (imp) values('" &
myread.GetValue(5) & "')"
'sqlcmd.Connection = sqlConn
'sqlcmd.ExecuteNonQuery()
Response.write (myread.getvalue(5))
Response.write("<BR>")
End While
sqlConn.Close()

Can anybody please let me know what am i doing wrong over here. Also is
there any method in ado.net like ado (Recordset.EOF) because i couldn't find
any method like this as well.
Thanks in advance.
 
S

shiv_koirala

Hi

Where are you reading the CSV file or loading the CSV file.Is the path
name having the CSV file name... Sqldatareader.read() return true if
there are records in datareader , which is equivalent to .eof and .bof
functionalities in old ADO.

Shivprasad Koirala
C# , VB.NET , SQL SERVER , ASP.NET Interview Questions
http://www.geocities.com/dotnetinterviews/
 
G

Guest

Hello shiv,

Thank you for your reply. I solved this problem. But yes for your concern
i'll answer the questions.
Yes the path name is returing true. I'm reading the file from web server in
a directory in there called import.
I'm putting the server.mappath() function and its working because if i
remove the file or change path it is actually giving me the error that the
file couldn't be found.
I have some more questions. In ASP sometimes we put any flag variable after
recordset.movenext to do manythings. How can i implement that functionality
in .net. Furthermore is there any property like recordcount in ado.net
because i couldn't find any. Since i'm new to .net so can you please tell me
if its there which object it lies with.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top