Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > populate array with sql table data vb.net

Reply
Thread Tools

populate array with sql table data vb.net

 
 
Sharon
Guest
Posts: n/a
 
      10-20-2006
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.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tp?=
Guest
Posts: n/a
 
      10-20-2006
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.
>
>

 
Reply With Quote
 
 
 
 
Sharon
Guest
Posts: n/a
 
      10-22-2006
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.
> >
> >


 
Reply With Quote
 
Sharon
Guest
Posts: n/a
 
      10-23-2006
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.
> >
> >


 
Reply With Quote
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tp?=
Guest
Posts: n/a
 
      10-27-2006
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.
> > >
> > >

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamically populate select option list via javascript array with sql data skywalker skywalker Javascript 4 07-22-2011 01:17 PM
How to populate a field in gridview with data FROM ANOTHER TABLE? Kurt of San Jose ASP .Net 0 04-04-2008 03:25 AM
How to populate a 2D array data into Excel using WIN32OLE Li Chen Ruby 3 01-21-2007 10:51 PM
Populate a popup window with clickable records from an Access DB and upon clicking, populate a selectbox on the original webpage with the clicked record Enjoy Life ASP General 2 02-23-2005 10:48 PM
Changing a html table when new data is entered into SQL table. Renie83 ASP General 1 07-09-2003 03:30 PM



Advertisments