473,386 Members | 1,738 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,386 software developers and data experts.

How to put an array into a table

Hello,

It should be a simple solution to this, I've just never done it and cannot
find any information so far.

I'm getting an array - the list of the files in the directory:

Dim dir As DirectoryInfo = New DirectoryInfo("\\10.0.0.150\FormLib")
Dim files() As FileInfo = dir.GetFiles("*.eps")

I need to put this array into a SQL server table. How can I do this?

I would appreciate your advice very much.

Thank you,

--
Peter Afonin
Nov 21 '05 #1
4 1123
// create connection object
// open the database connection
foreach(FileInfo myFile in files)
{
// read the file into whatever variables if you please.
// create a command object
// populate the stored procedure if you are using one
// or populate the insert command

// execute the command using ExecuteNonQuery
// dispose the object
}
// close the connection
// dispose the connection

i am saying that you need to open the connection before the foreach because
you might have hell lot of files and you dont want to keep opening database
connection.
i have never reused command object but even that might be worth a try.

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Peter Afonin" <pe***@gudzon.net> wrote in message
news:#G**************@TK2MSFTNGP12.phx.gbl...
Hello,

It should be a simple solution to this, I've just never done it and cannot
find any information so far.

I'm getting an array - the list of the files in the directory:

Dim dir As DirectoryInfo = New DirectoryInfo("\\10.0.0.150\FormLib")
Dim files() As FileInfo = dir.GetFiles("*.eps")

I need to put this array into a SQL server table. How can I do this?

I would appreciate your advice very much.

Thank you,

--
Peter Afonin

Nov 21 '05 #2
Thank you very much, Hermit, it worked!

Peter

Dim dir As DirectoryInfo = New DirectoryInfo("\\10.0.0.150\FormLib")
Dim files() As FileInfo = dir.GetFiles("*.eps")
Dim file As FileInfo
oCnn.ConnectionString = smi_class.Constants.Wip7bConnectionString
oCmd.Connection = oCnn
oCmd.CommandType = CommandType.StoredProcedure
oCmd.CommandText = "dbo.uspAddEPS"
oCnn.Open()
With oCmd.Parameters
..Add("@File", SqlDbType.Char, 10).Direction = ParameterDirection.Input
End With
For Each file In files
oCmd.Parameters.Item("@File").Value = Left(file.Name.ToString,
Len(file.Name.ToString) - 4)
oCmd.ExecuteNonQuery()
Next

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:#i**************@tk2msftngp13.phx.gbl...
// create connection object
// open the database connection
foreach(FileInfo myFile in files)
{
// read the file into whatever variables if you please.
// create a command object
// populate the stored procedure if you are using one
// or populate the insert command

// execute the command using ExecuteNonQuery
// dispose the object
}
// close the connection
// dispose the connection

i am saying that you need to open the connection before the foreach because you might have hell lot of files and you dont want to keep opening database connection.
i have never reused command object but even that might be worth a try.

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Peter Afonin" <pe***@gudzon.net> wrote in message
news:#G**************@TK2MSFTNGP12.phx.gbl...
Hello,

It should be a simple solution to this, I've just never done it and cannot find any information so far.

I'm getting an array - the list of the files in the directory:

Dim dir As DirectoryInfo = New DirectoryInfo("\\10.0.0.150\FormLib")
Dim files() As FileInfo = dir.GetFiles("*.eps")

I need to put this array into a SQL server table. How can I do this?

I would appreciate your advice very much.

Thank you,

--
Peter Afonin


Nov 21 '05 #3
Great... hope you are closing and disposing the connection object :)

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Peter Afonin" <pe***@gudzon.net> wrote in message
news:#y**************@TK2MSFTNGP15.phx.gbl...
Thank you very much, Hermit, it worked!

Peter

Dim dir As DirectoryInfo = New DirectoryInfo("\\10.0.0.150\FormLib")
Dim files() As FileInfo = dir.GetFiles("*.eps")
Dim file As FileInfo
oCnn.ConnectionString = smi_class.Constants.Wip7bConnectionString
oCmd.Connection = oCnn
oCmd.CommandType = CommandType.StoredProcedure
oCmd.CommandText = "dbo.uspAddEPS"
oCnn.Open()
With oCmd.Parameters
.Add("@File", SqlDbType.Char, 10).Direction = ParameterDirection.Input
End With
For Each file In files
oCmd.Parameters.Item("@File").Value = Left(file.Name.ToString,
Len(file.Name.ToString) - 4)
oCmd.ExecuteNonQuery()
Next

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:#i**************@tk2msftngp13.phx.gbl...
// create connection object
// open the database connection
foreach(FileInfo myFile in files)
{
// read the file into whatever variables if you please.
// create a command object
// populate the stored procedure if you are using one
// or populate the insert command

// execute the command using ExecuteNonQuery
// dispose the object
}
// close the connection
// dispose the connection

i am saying that you need to open the connection before the foreach

because
you might have hell lot of files and you dont want to keep opening

database
connection.
i have never reused command object but even that might be worth a try.

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Peter Afonin" <pe***@gudzon.net> wrote in message
news:#G**************@TK2MSFTNGP12.phx.gbl...
Hello,

It should be a simple solution to this, I've just never done it and cannot find any information so far.

I'm getting an array - the list of the files in the directory:

Dim dir As DirectoryInfo = New DirectoryInfo("\\10.0.0.150\FormLib")
Dim files() As FileInfo = dir.GetFiles("*.eps")

I need to put this array into a SQL server table. How can I do this?

I would appreciate your advice very much.

Thank you,

--
Peter Afonin



Nov 21 '05 #4
Oh yes, always. Thanks.

Peter

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:OZ**************@TK2MSFTNGP15.phx.gbl...
Great... hope you are closing and disposing the connection object :)

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Peter Afonin" <pe***@gudzon.net> wrote in message
news:#y**************@TK2MSFTNGP15.phx.gbl...
Thank you very much, Hermit, it worked!

Peter

Dim dir As DirectoryInfo = New DirectoryInfo("\\10.0.0.150\FormLib")
Dim files() As FileInfo = dir.GetFiles("*.eps")
Dim file As FileInfo
oCnn.ConnectionString = smi_class.Constants.Wip7bConnectionString
oCmd.Connection = oCnn
oCmd.CommandType = CommandType.StoredProcedure
oCmd.CommandText = "dbo.uspAddEPS"
oCnn.Open()
With oCmd.Parameters
.Add("@File", SqlDbType.Char, 10).Direction = ParameterDirection.Input
End With
For Each file In files
oCmd.Parameters.Item("@File").Value = Left(file.Name.ToString,
Len(file.Name.ToString) - 4)
oCmd.ExecuteNonQuery()
Next

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message news:#i**************@tk2msftngp13.phx.gbl...
// create connection object
// open the database connection
foreach(FileInfo myFile in files)
{
// read the file into whatever variables if you please.
// create a command object
// populate the stored procedure if you are using one
// or populate the insert command

// execute the command using ExecuteNonQuery
// dispose the object
}
// close the connection
// dispose the connection

i am saying that you need to open the connection before the foreach

because
you might have hell lot of files and you dont want to keep opening

database
connection.
i have never reused command object but even that might be worth a try.

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Peter Afonin" <pe***@gudzon.net> wrote in message
news:#G**************@TK2MSFTNGP12.phx.gbl...
> Hello,
>
> It should be a simple solution to this, I've just never done it and

cannot
> find any information so far.
>
> I'm getting an array - the list of the files in the directory:
>
> Dim dir As DirectoryInfo = New DirectoryInfo("\\10.0.0.150\FormLib")
> Dim files() As FileInfo = dir.GetFiles("*.eps")
>
> I need to put this array into a SQL server table. How can I do this?
>
> I would appreciate your advice very much.
>
> Thank you,
>
> --
> Peter Afonin
>
>



Nov 21 '05 #5

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

Similar topics

9
by: Rob Thorpe | last post by:
I have a set of data structures that are collected together in array. This array is in turn packaged in a struct itself. The structs look like this:- struct index_entry_t { char *id; char...
7
by: Roman Mashak | last post by:
Hello, All! I wonder is it possible to define an array containing strings, not single characters? What I want is array 'table' that will have N elements, and every element is a strings tailoring...
0
by: evilbungle | last post by:
Good Morning, I am trying to build an application that will take the details from an access database and use them as log in details but I can not get the App to open the table as I keep getting...
1
by: romepatel | last post by:
Hello, I have an table, and i want to update whole row dynamically, according the user entered data...... below is the example, <html> <script type="text/javascript"> function doThis() {...
2
by: bluemoon9 | last post by:
Hi all, I have this querry, when I run the query, it makes the table name "tmaCustomer", but I would like to set the field "TotalCompliant" as Text, instead of Number, any idea? When the table has...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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
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...

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.