How to put an array into a table

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Afonin

    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\Fo rmLib")
    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


  • Hermit Dave

    #2
    Re: How to put an array into a table

    // create connection object
    // open the database connection
    foreach(FileInf o 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" <peter@gudzon.n et> wrote in message
    news:#GLA$nclEH A.3612@TK2MSFTN GP12.phx.gbl...[color=blue]
    > 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\Fo rmLib")
    > 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
    >
    >[/color]


    Comment

    • Peter Afonin

      #3
      Re: How to put an array into a table

      Thank you very much, Hermit, it worked!

      Peter

      Dim dir As DirectoryInfo = New DirectoryInfo(" \\10.0.0.150\Fo rmLib")
      Dim files() As FileInfo = dir.GetFiles("* .eps")
      Dim file As FileInfo
      oCnn.Connection String = smi_class.Const ants.Wip7bConne ctionString
      oCmd.Connection = oCnn
      oCmd.CommandTyp e = CommandType.Sto redProcedure
      oCmd.CommandTex t = "dbo.uspAdd EPS"
      oCnn.Open()
      With oCmd.Parameters
      ..Add("@File", SqlDbType.Char, 10).Direction = ParameterDirect ion.Input
      End With
      For Each file In files
      oCmd.Parameters .Item("@File"). Value = Left(file.Name. ToString,
      Len(file.Name.T oString) - 4)
      oCmd.ExecuteNon Query()
      Next

      "Hermit Dave" <hermitd.REMOVE @CAPS.AND.DOTS. hotmail.com> wrote in message
      news:#inz6TdlEH A.3988@tk2msftn gp13.phx.gbl...[color=blue]
      > // create connection object
      > // open the database connection
      > foreach(FileInf o 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[/color]
      because[color=blue]
      > you might have hell lot of files and you dont want to keep opening[/color]
      database[color=blue]
      > connection.
      > i have never reused command object but even that might be worth a try.
      >
      > --
      >
      > Regards,
      >
      > Hermit Dave
      > (http://hdave.blogspot.com)
      > "Peter Afonin" <peter@gudzon.n et> wrote in message
      > news:#GLA$nclEH A.3612@TK2MSFTN GP12.phx.gbl...[color=green]
      > > Hello,
      > >
      > > It should be a simple solution to this, I've just never done it and[/color][/color]
      cannot[color=blue][color=green]
      > > 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\Fo rmLib")
      > > 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
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Hermit Dave

        #4
        Re: How to put an array into a table

        Great... hope you are closing and disposing the connection object :)

        --

        Regards,

        Hermit Dave
        (http://hdave.blogspot.com)
        "Peter Afonin" <peter@gudzon.n et> wrote in message
        news:#yaOp4elEH A.2140@TK2MSFTN GP15.phx.gbl...[color=blue]
        > Thank you very much, Hermit, it worked!
        >
        > Peter
        >
        > Dim dir As DirectoryInfo = New DirectoryInfo(" \\10.0.0.150\Fo rmLib")
        > Dim files() As FileInfo = dir.GetFiles("* .eps")
        > Dim file As FileInfo
        > oCnn.Connection String = smi_class.Const ants.Wip7bConne ctionString
        > oCmd.Connection = oCnn
        > oCmd.CommandTyp e = CommandType.Sto redProcedure
        > oCmd.CommandTex t = "dbo.uspAdd EPS"
        > oCnn.Open()
        > With oCmd.Parameters
        > .Add("@File", SqlDbType.Char, 10).Direction = ParameterDirect ion.Input
        > End With
        > For Each file In files
        > oCmd.Parameters .Item("@File"). Value = Left(file.Name. ToString,
        > Len(file.Name.T oString) - 4)
        > oCmd.ExecuteNon Query()
        > Next
        >
        > "Hermit Dave" <hermitd.REMOVE @CAPS.AND.DOTS. hotmail.com> wrote in message
        > news:#inz6TdlEH A.3988@tk2msftn gp13.phx.gbl...[color=green]
        > > // create connection object
        > > // open the database connection
        > > foreach(FileInf o 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[/color]
        > because[color=green]
        > > you might have hell lot of files and you dont want to keep opening[/color]
        > database[color=green]
        > > connection.
        > > i have never reused command object but even that might be worth a try.
        > >
        > > --
        > >
        > > Regards,
        > >
        > > Hermit Dave
        > > (http://hdave.blogspot.com)
        > > "Peter Afonin" <peter@gudzon.n et> wrote in message
        > > news:#GLA$nclEH A.3612@TK2MSFTN GP12.phx.gbl...[color=darkred]
        > > > Hello,
        > > >
        > > > It should be a simple solution to this, I've just never done it and[/color][/color]
        > cannot[color=green][color=darkred]
        > > > 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\Fo rmLib")
        > > > 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
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Peter Afonin

          #5
          Re: How to put an array into a table

          Oh yes, always. Thanks.

          Peter

          "Hermit Dave" <hermitd.REMOVE @CAPS.AND.DOTS. hotmail.com> wrote in message
          news:OZ0fREflEH A.3896@TK2MSFTN GP15.phx.gbl...[color=blue]
          > Great... hope you are closing and disposing the connection object :)
          >
          > --
          >
          > Regards,
          >
          > Hermit Dave
          > (http://hdave.blogspot.com)
          > "Peter Afonin" <peter@gudzon.n et> wrote in message
          > news:#yaOp4elEH A.2140@TK2MSFTN GP15.phx.gbl...[color=green]
          > > Thank you very much, Hermit, it worked!
          > >
          > > Peter
          > >
          > > Dim dir As DirectoryInfo = New DirectoryInfo(" \\10.0.0.150\Fo rmLib")
          > > Dim files() As FileInfo = dir.GetFiles("* .eps")
          > > Dim file As FileInfo
          > > oCnn.Connection String = smi_class.Const ants.Wip7bConne ctionString
          > > oCmd.Connection = oCnn
          > > oCmd.CommandTyp e = CommandType.Sto redProcedure
          > > oCmd.CommandTex t = "dbo.uspAdd EPS"
          > > oCnn.Open()
          > > With oCmd.Parameters
          > > .Add("@File", SqlDbType.Char, 10).Direction = ParameterDirect ion.Input
          > > End With
          > > For Each file In files
          > > oCmd.Parameters .Item("@File"). Value = Left(file.Name. ToString,
          > > Len(file.Name.T oString) - 4)
          > > oCmd.ExecuteNon Query()
          > > Next
          > >
          > > "Hermit Dave" <hermitd.REMOVE @CAPS.AND.DOTS. hotmail.com> wrote in[/color][/color]
          message[color=blue][color=green]
          > > news:#inz6TdlEH A.3988@tk2msftn gp13.phx.gbl...[color=darkred]
          > > > // create connection object
          > > > // open the database connection
          > > > foreach(FileInf o 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[/color]
          > > because[color=darkred]
          > > > you might have hell lot of files and you dont want to keep opening[/color]
          > > database[color=darkred]
          > > > connection.
          > > > i have never reused command object but even that might be worth a try.
          > > >
          > > > --
          > > >
          > > > Regards,
          > > >
          > > > Hermit Dave
          > > > (http://hdave.blogspot.com)
          > > > "Peter Afonin" <peter@gudzon.n et> wrote in message
          > > > news:#GLA$nclEH A.3612@TK2MSFTN GP12.phx.gbl...
          > > > > Hello,
          > > > >
          > > > > It should be a simple solution to this, I've just never done it and[/color]
          > > cannot[color=darkred]
          > > > > 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\Fo rmLib")
          > > > > 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
          > > > >
          > > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          Working...