populate array with sql table data vb.net

Discussion in 'ASP .Net' started by Sharon, Oct 20, 2006.

  1. Sharon

    Sharon Guest

    hello,

    I wanted to populate an array with the data from sql table, but not
    sure how to go about it.

    This is the array iam using at present, but i dont want to provide the
    values. Instead i want to query them from sql table t_holidays.

    Dim HolidayList() As Date = {#7/4/2006#, #7/6/2006#, #7/13/2006#,
    #7/19/2006#, #12/24/2006#, #12/25/2006#, #12/29/2006#, #1/1/2007#}

    Any suggestions how to go about this one. Your time is greatly
    appreciated.

    cheers, Sharon.
    Sharon, Oct 20, 2006
    #1
    1. Advertising

  2. Simple example (i assume you have basic knowledge about ADO.NET)

    Imports System.Data
    Imports System.Data.SqlClient

    Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.Load

    Dim dates As System.Collections.Generic.List(Of DateTime) = GetDates()

    End Sub

    Private Const ConnectionString As String =
    "server=ServerName;uid=UserName;password=Password;database=DatebaseName"

    Private Function GetDates() As System.Collections.Generic.List(Of DateTime)

    Dim result As New System.Collections.Generic.List(Of DateTime)
    Dim connection As New SqlConnection(ConnectionString)
    Dim command As New SqlCommand("select DateColumn FROM TableName WHERE
    Condition", connection)
    Dim reader As SqlDataReader

    Try

    connection.Open()
    reader = command.ExecuteReader()

    While reader.Read()
    result.Add(reader.GetDateTime(0))
    End While

    Catch ex As Exception
    Throw ex
    Finally
    connection.Dispose()
    End Try

    Return result

    End Function

    End Class


    --
    Milosz Skalecki
    MCP, MCAD


    "Sharon" wrote:

    > hello,
    >
    > I wanted to populate an array with the data from sql table, but not
    > sure how to go about it.
    >
    > This is the array iam using at present, but i dont want to provide the
    > values. Instead i want to query them from sql table t_holidays.
    >
    > Dim HolidayList() As Date = {#7/4/2006#, #7/6/2006#, #7/13/2006#,
    > #7/19/2006#, #12/24/2006#, #12/25/2006#, #12/29/2006#, #1/1/2007#}
    >
    > Any suggestions how to go about this one. Your time is greatly
    > appreciated.
    >
    > cheers, Sharon.
    >
    >
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tp?=, Oct 20, 2006
    #2
    1. Advertising

  3. Sharon

    Sharon Guest

    Thanks for the Reply, But its giving me an error

    System.Collections.Generic.List is not defined, Please let me know
    where did it went wrong.

    cheers, Sharon.


    Milosz Skalecki wrote:
    > Simple example (i assume you have basic knowledge about ADO.NET)
    >
    > Imports System.Data
    > Imports System.Data.SqlClient
    >
    > Partial Class _Default
    > Inherits System.Web.UI.Page
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    >
    > Dim dates As System.Collections.Generic.List(Of DateTime) = GetDates()
    >
    > End Sub
    >
    > Private Const ConnectionString As String =
    > "server=ServerName;uid=UserName;password=Password;database=DatebaseName"
    >
    > Private Function GetDates() As System.Collections.Generic.List(Of DateTime)
    >
    > Dim result As New System.Collections.Generic.List(Of DateTime)
    > Dim connection As New SqlConnection(ConnectionString)
    > Dim command As New SqlCommand("select DateColumn FROM TableName WHERE
    > Condition", connection)
    > Dim reader As SqlDataReader
    >
    > Try
    >
    > connection.Open()
    > reader = command.ExecuteReader()
    >
    > While reader.Read()
    > result.Add(reader.GetDateTime(0))
    > End While
    >
    > Catch ex As Exception
    > Throw ex
    > Finally
    > connection.Dispose()
    > End Try
    >
    > Return result
    >
    > End Function
    >
    > End Class
    >
    >
    > --
    > Milosz Skalecki
    > MCP, MCAD
    >
    >
    > "Sharon" wrote:
    >
    > > hello,
    > >
    > > I wanted to populate an array with the data from sql table, but not
    > > sure how to go about it.
    > >
    > > This is the array iam using at present, but i dont want to provide the
    > > values. Instead i want to query them from sql table t_holidays.
    > >
    > > Dim HolidayList() As Date = {#7/4/2006#, #7/6/2006#, #7/13/2006#,
    > > #7/19/2006#, #12/24/2006#, #12/25/2006#, #12/29/2006#, #1/1/2007#}
    > >
    > > Any suggestions how to go about this one. Your time is greatly
    > > appreciated.
    > >
    > > cheers, Sharon.
    > >
    > >
    Sharon, Oct 23, 2006
    #3
  4. Sharon

    Sharon Guest

    I am using .NET Framework version, is this class available in this
    version
    Milosz Skalecki wrote:
    > Simple example (i assume you have basic knowledge about ADO.NET)
    >
    > Imports System.Data
    > Imports System.Data.SqlClient
    >
    > Partial Class _Default
    > Inherits System.Web.UI.Page
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    >
    > Dim dates As System.Collections.Generic.List(Of DateTime) = GetDates()
    >
    > End Sub
    >
    > Private Const ConnectionString As String =
    > "server=ServerName;uid=UserName;password=Password;database=DatebaseName"
    >
    > Private Function GetDates() As System.Collections.Generic.List(Of DateTime)
    >
    > Dim result As New System.Collections.Generic.List(Of DateTime)
    > Dim connection As New SqlConnection(ConnectionString)
    > Dim command As New SqlCommand("select DateColumn FROM TableName WHERE
    > Condition", connection)
    > Dim reader As SqlDataReader
    >
    > Try
    >
    > connection.Open()
    > reader = command.ExecuteReader()
    >
    > While reader.Read()
    > result.Add(reader.GetDateTime(0))
    > End While
    >
    > Catch ex As Exception
    > Throw ex
    > Finally
    > connection.Dispose()
    > End Try
    >
    > Return result
    >
    > End Function
    >
    > End Class
    >
    >
    > --
    > Milosz Skalecki
    > MCP, MCAD
    >
    >
    > "Sharon" wrote:
    >
    > > hello,
    > >
    > > I wanted to populate an array with the data from sql table, but not
    > > sure how to go about it.
    > >
    > > This is the array iam using at present, but i dont want to provide the
    > > values. Instead i want to query them from sql table t_holidays.
    > >
    > > Dim HolidayList() As Date = {#7/4/2006#, #7/6/2006#, #7/13/2006#,
    > > #7/19/2006#, #12/24/2006#, #12/25/2006#, #12/29/2006#, #1/1/2007#}
    > >
    > > Any suggestions how to go about this one. Your time is greatly
    > > appreciated.
    > >
    > > cheers, Sharon.
    > >
    > >
    Sharon, Oct 23, 2006
    #4
  5. Howdy,

    i automatically assumed you were using framework 2.0. Please use
    System.Collections.ArrayList instead of
    System.Collections.Generic.List(Of DateTime)

    regards

    --
    Milosz Skalecki
    MCP, MCAD


    "Sharon" wrote:

    > I am using .NET Framework version, is this class available in this
    > version
    > Milosz Skalecki wrote:
    > > Simple example (i assume you have basic knowledge about ADO.NET)
    > >
    > > Imports System.Data
    > > Imports System.Data.SqlClient
    > >
    > > Partial Class _Default
    > > Inherits System.Web.UI.Page
    > >
    > > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > > System.EventArgs) Handles Me.Load
    > >
    > > Dim dates As System.Collections.Generic.List(Of DateTime) = GetDates()
    > >
    > > End Sub
    > >
    > > Private Const ConnectionString As String =
    > > "server=ServerName;uid=UserName;password=Password;database=DatebaseName"
    > >
    > > Private Function GetDates() As System.Collections.Generic.List(Of DateTime)
    > >
    > > Dim result As New System.Collections.Generic.List(Of DateTime)
    > > Dim connection As New SqlConnection(ConnectionString)
    > > Dim command As New SqlCommand("select DateColumn FROM TableName WHERE
    > > Condition", connection)
    > > Dim reader As SqlDataReader
    > >
    > > Try
    > >
    > > connection.Open()
    > > reader = command.ExecuteReader()
    > >
    > > While reader.Read()
    > > result.Add(reader.GetDateTime(0))
    > > End While
    > >
    > > Catch ex As Exception
    > > Throw ex
    > > Finally
    > > connection.Dispose()
    > > End Try
    > >
    > > Return result
    > >
    > > End Function
    > >
    > > End Class
    > >
    > >
    > > --
    > > Milosz Skalecki
    > > MCP, MCAD
    > >
    > >
    > > "Sharon" wrote:
    > >
    > > > hello,
    > > >
    > > > I wanted to populate an array with the data from sql table, but not
    > > > sure how to go about it.
    > > >
    > > > This is the array iam using at present, but i dont want to provide the
    > > > values. Instead i want to query them from sql table t_holidays.
    > > >
    > > > Dim HolidayList() As Date = {#7/4/2006#, #7/6/2006#, #7/13/2006#,
    > > > #7/19/2006#, #12/24/2006#, #12/25/2006#, #12/29/2006#, #1/1/2007#}
    > > >
    > > > Any suggestions how to go about this one. Your time is greatly
    > > > appreciated.
    > > >
    > > > cheers, Sharon.
    > > >
    > > >

    >
    >
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tp?=, Oct 27, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kurt of San Jose
    Replies:
    0
    Views:
    620
    Kurt of San Jose
    Apr 4, 2008
  2. Renie83
    Replies:
    1
    Views:
    297
    Ray at
    Jul 9, 2003
  3. Enjoy Life
    Replies:
    2
    Views:
    259
    Roland Hall
    Feb 23, 2005
  4. Li Chen
    Replies:
    3
    Views:
    121
  5. skywalker skywalker
    Replies:
    4
    Views:
    2,168
    Evertjan.
    Jul 22, 2011
Loading...

Share This Page