473,397 Members | 1,969 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,397 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 18 '05 #1
4 1452
// 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 18 '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 18 '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 18 '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 18 '05 #5

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

Similar topics

8
by: michi | last post by:
Hello everybody, I have following problem: I have an array of pointers to structures: table* tab = new table; and structure table is like this: struct table{ CSLL::node* chain;
5
by: deko | last post by:
I use a For Each... Next loop like this: For Each varFnm In Array("This", "That", "OtherThing", "Foo", "Bar") RunSql ("UPDATE.... bla bla bla) Next But the exact same elements of the Array...
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...
5
by: Chris H | last post by:
Okay, I am trying to us a varialble with a list of number values as my data for an array, yet when I do this it doesnt return any values from the array, i was able to temporarily fix the proble by...
1
by: assgar | last post by:
Hi I need help solving a porblem. I have a form that displays a checkbox, service code, description and dropdown with fees on each row. The fee_money and unit array only returns a...
1
by: shailajaAdiga | last post by:
Hi All, there are 4 different categories which each month will bw updated. In each category(source),there are many editions. I have to display 6months updates. its like one is month array which...
10
by: Bob Bedford | last post by:
Hi all, it's there any simple way to create an array of years and months dynamically (2 loops) for an associative array ? I've tried this so far: (having an error on last line with the "=>"...
6
by: lukasso | last post by:
Hi, this is my code that should produce something like a timetable for a few days with each day divided into 30 minute pieces. It makes query from MySQL and then creates a 2d $array which then is to...
2
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error...
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
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
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,...
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.