I'm hoping someone will have a suggestion.
Basically what i am doing is reading a csv file into a table, but I only want to read in certain columns, so the idea was read the csv file into a dataset and then select the relevent columns from the dataset into another......
But I keep getting an error saying I've a syntax error in my script. I'm not sure if trying to run a fill on a new dataset referencing another one is possible:
It goes something like this......
'txtFileName.text is coming from for where user has given the filename
Dim selectcmdstr As String = "SELECT * FROM " & txtFileName.Text
Dim cd As New Odbc.OdbcCommand(selectcmdstr, cnConn) 'text.csv", cnConn) ' & txtFileName.Text, cnConn)
cnConn.Open()
dtable1Adapt.SelectCommand = cd
dtable1Adapt.Fill(dataset1, "Extract")
'this all works to here
' I generate a sql command of columns needed based on data stored in database
Dim selectFormStr ="Select [Average Cost [N]]] * [End Qty] as MarketValAvg, [End Qty] * [End Price [N]]] as MarketValue from dataset1.tables(1).ToString()"
Dim cd3 As New Odbc.OdbcCommand(selectFormStr, cnConn)
dtable3Adapt.SelectCommand = cd3
dtable3Adapt.Fill(dataset2, "Rules") 'FAILS HERE
cnConn.Close()
Any suggestions on how to approach/resolve much appreciated!
3 10198
If you dont want a particular row, you can use the remove method to remove it from the dataset.
If you dont want a particular row, you can use the remove method to remove it from the dataset.
The problem is I only want certain columns, but I need to keep all rows for those columns.
Just realising removing columns won't really work, since part of what I wanted to do was generate a new column from 2 columns in a dataset. Eg selecting the results of Price * Quantity into a new column Cost whilst also having the columns Price and Quantity in the new dataset.
Just remove all the columns except Price and Quantity won't do that....
'Reading data from CSV and makeing as a table format sending into dataset
'inserting data into ms-access from that dataset
Public Function export_data_from_csv_to_Access()
Try
'Csv folder path
Dim folder As String = Module1.GetMyAppSetting.Sbuzz_AppSettings(Module1. XMLLocation, "ExtractFolderpath")
'Csv file path
Dim filename As String = Module1.GetMyAppSetting.Sbuzz_AppSettings(Module1. XMLLocation, "extractFilename")
'sending into file system
Dim file As System.IO.FileInfo = New System.IO.FileInfo(folder + filename)
If file.Exists Then
'Split the csv file with (",") and making data as in table format
Dim myTable As DataTable = New DataTable("MyTable")
Dim i As Integer
Dim myRow As DataRow
Dim fieldValues As String()
Dim f As IO.File
Dim myReader As StreamReader
myReader = f.OpenText(folder + filename)
Dim strLine As String = myReader.ReadLine()
myReader.ReadLine().Remove(0, 1)
fieldValues = myReader.ReadLine().Split(New Char() {","})
'Add columns to table
For i = 0 To fieldValues.Length() - 1
myTable.Columns.Add(New DataColumn("Field" & i))
Next
myRow = myTable.NewRow
'Adding Rows to table
For i = 0 To 5
Dim k As String = fieldValues(i).ToString
Dim kk As Integer = fieldValues.Length()
myRow.Item(i) = fieldValues(i).ToString
Next
myTable.Rows.Add(myRow)
'All rows and cloumns making as table format
While myReader.Peek() <> -1
fieldValues = myReader.ReadLine().Split(New Char() {","})
myRow = myTable.NewRow
For i = 0 To 5
myRow.Item(i) = fieldValues(i).ToString
Next
myTable.Rows.Add(myRow)
End While
'Table sending into dataset
Dim ds As New DataSet
ds.Tables.Add(myTable)
'Deleting data from Geoip.Mdb file
Delete_Data()
For i = 0 To ds.Tables("myTable").Rows.Count - 1 '
'Insert data into Geoip.Mdb from Dataset(Made from csv file)
mdbcon = Module1.OpenMdbconnection()
'From that csv reading time we can get some charectes like {',",/} to remove those
strToRemove1 = RemoveChars(ds.Tables("myTable").Rows(i).ItemArray .GetValue(0))
strToRemove2 = RemoveChars(ds.Tables("myTable").Rows(i).ItemArray .GetValue(1))
strToRemove3 = RemoveChars(ds.Tables("myTable").Rows(i).ItemArray .GetValue(2))
strToRemove4 = RemoveChars(ds.Tables("myTable").Rows(i).ItemArray .GetValue(3))
strToRemove5 = RemoveChars(ds.Tables("myTable").Rows(i).ItemArray .GetValue(4))
strToRemove6 = RemoveChars(ds.Tables("myTable").Rows(i).ItemArray .GetValue(5))
Dim MdbCmdTxt_InsertData As String = "Insert into Geoip(beginIp,endip,beginIpNum,endIpNum,countryCod e,countryName) values('" & strToRemove1 & "','" & strToRemove2 & "','" & strToRemove3 & "','" & strToRemove4 & "','" & strToRemove5 & "','" & strToRemove6 & "')"
Dim MdbcmdIns As New OleDbCommand(MdbCmdTxt_InsertData, Mdbcon)
MdbcmdIns.ExecuteNonQuery()
MdbcmdIns.Connection.Close()
Mdbcon.Close()
Next i
End If
Module1.to_Write_Status_file("Completed from Csv to Ms-Access")
Catch ex As Exception
Module1.Error_Status = "Error From Export"
Module1.Error_type = ex.Message
End Try
End Function
Sign in to post your reply or Sign up for a free account.
Similar topics
by: octaviansen |
last post by:
Hi,
I am experiencing some weird problems with an ASP.NET web application
that is making use of System.Data.DataSet and System.Data.DataRow
classes.
On a machine with single CPU, the...
|
by: Greg Cyrus |
last post by:
Hi,
i have created a function to open a Databse by OLEDB and fill it into a
System.Data.DataSet-Objekt by oleDBAdapter.Fill-Mehtod..
Now I want to assign this DataSet to a normal...
|
by: Han Lim |
last post by:
Dear All,
I have an application written by VB.Net with connect to a
Microsoft Access database.
One of the forms is to select data using oleAdapter and fill it
into a dataset. In the oleAdapter, i...
|
by: Optimus |
last post by:
Hi everyone,
I currently develop an application in vs.net 2005 with vb.net.
I was trying to use typed dataset and I've got in trouble for
converting untyped dataset
into Typed DataSet. I don't...
|
by: bsn |
last post by:
Hello NG
I want to select data from another DB, and use this data in currentDB.
I have this SQL in a VBA procedure:
Sql = "SELECT * FROM Firma "
It is not working
Any suggestions...
...
|
by: coffeesin |
last post by:
Hi,
I have a Table containing these fields: id-no, cold, cold ever, cold date,flu,flu ever and flu date. (The properties of id-no, cold,cold ever,flu,flu ever are set as Numbers.)
What i want...
|
by: marylipscomb |
last post by:
I am using VB.NET. I am trying to connect a button so that when it is clicked the gridview pops up the data.
Partial Class Switchboard
Inherits System.Web.UI.Page
Protected Sub...
|
by: thread |
last post by:
Hi All
i'm building a database in access and i want to restrict permissions.
from the access i can just limit the posiblity to unhide an hidden
table and in this way i can preventing the users...
|
by: prabunewindia |
last post by:
Hi,
for my project, i am using session to store the user's information like userid, username...
Also i am storing the dataset, which is having the datas for the particular user to avoid trip to...
|
by: =?Utf-8?B?RnJhbmsgVXJheQ==?= |
last post by:
Hi all
I have a DataSet with 2 tables.
Now I want to select data like a INNER JOIN from these tables.
In SQL Syntax I would write:
SELECT *
FROM table1 t1
INNER JOIN table2 t2
ON t1.f1 =...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |