473,803 Members | 3,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

populate array with sql table data vb.net

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.

Oct 20 '06 #1
4 9629
Simple example (i assume you have basic knowledge about ADO.NET)

Imports System.Data
Imports System.Data.Sql Client

Partial Class _Default
Inherits System.Web.UI.P age

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

Dim dates As System.Collecti ons.Generic.Lis t(Of DateTime) = GetDates()

End Sub

Private Const ConnectionStrin g As String =
"server=ServerN ame;uid=UserNam e;password=Pass word;database=D atebaseName"

Private Function GetDates() As System.Collecti ons.Generic.Lis t(Of DateTime)

Dim result As New System.Collecti ons.Generic.Lis t(Of DateTime)
Dim connection As New SqlConnection(C onnectionString )
Dim command As New SqlCommand("sel ect DateColumn FROM TableName WHERE
Condition", connection)
Dim reader As SqlDataReader

Try

connection.Open ()
reader = command.Execute Reader()

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

Catch ex As Exception
Throw ex
Finally
connection.Disp ose()
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.

Oct 20 '06 #2
Thanks for the Reply, But its giving me an error

System.Collecti ons.Generic.Lis t 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.Sql Client

Partial Class _Default
Inherits System.Web.UI.P age

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

Dim dates As System.Collecti ons.Generic.Lis t(Of DateTime) = GetDates()

End Sub

Private Const ConnectionStrin g As String =
"server=ServerN ame;uid=UserNam e;password=Pass word;database=D atebaseName"

Private Function GetDates() As System.Collecti ons.Generic.Lis t(Of DateTime)

Dim result As New System.Collecti ons.Generic.Lis t(Of DateTime)
Dim connection As New SqlConnection(C onnectionString )
Dim command As New SqlCommand("sel ect DateColumn FROM TableName WHERE
Condition", connection)
Dim reader As SqlDataReader

Try

connection.Open ()
reader = command.Execute Reader()

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

Catch ex As Exception
Throw ex
Finally
connection.Disp ose()
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.
Oct 22 '06 #3
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.Sql Client

Partial Class _Default
Inherits System.Web.UI.P age

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

Dim dates As System.Collecti ons.Generic.Lis t(Of DateTime) = GetDates()

End Sub

Private Const ConnectionStrin g As String =
"server=ServerN ame;uid=UserNam e;password=Pass word;database=D atebaseName"

Private Function GetDates() As System.Collecti ons.Generic.Lis t(Of DateTime)

Dim result As New System.Collecti ons.Generic.Lis t(Of DateTime)
Dim connection As New SqlConnection(C onnectionString )
Dim command As New SqlCommand("sel ect DateColumn FROM TableName WHERE
Condition", connection)
Dim reader As SqlDataReader

Try

connection.Open ()
reader = command.Execute Reader()

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

Catch ex As Exception
Throw ex
Finally
connection.Disp ose()
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.
Oct 23 '06 #4
Howdy,

i automatically assumed you were using framework 2.0. Please use
System.Collecti ons.ArrayList instead of
System.Collecti ons.Generic.Lis t(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.Sql Client

Partial Class _Default
Inherits System.Web.UI.P age

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

Dim dates As System.Collecti ons.Generic.Lis t(Of DateTime) = GetDates()

End Sub

Private Const ConnectionStrin g As String =
"server=ServerN ame;uid=UserNam e;password=Pass word;database=D atebaseName"

Private Function GetDates() As System.Collecti ons.Generic.Lis t(Of DateTime)

Dim result As New System.Collecti ons.Generic.Lis t(Of DateTime)
Dim connection As New SqlConnection(C onnectionString )
Dim command As New SqlCommand("sel ect DateColumn FROM TableName WHERE
Condition", connection)
Dim reader As SqlDataReader

Try

connection.Open ()
reader = command.Execute Reader()

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

Catch ex As Exception
Throw ex
Finally
connection.Disp ose()
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.
>
>

Oct 27 '06 #5

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

Similar topics

7
15030
by: Sugapablo | last post by:
Before I go building this, I want to know if it already exists. I need some PHP code that will read a web page and return all text that comes between <td></td> tags in an array. So if there were three tables on that page, it would return the first table's fourth row, third column in a variable such as: $tableArray // ^ ^ ^ - 2nd <td></td>
2
6760
by: harry | last post by:
Hi All ! I open a table in Query Analyzer by right clicking on it and selecting 'Open' and when the data is displayed in the view pane I would like to be able to edit it. It seems however that tables marked as read only (as shown on the top bar e.g. SQL Query Analyzer - ) can not be edited whereas the one that do not have that attribute infront of the name I can edit. Is there a way I can change the read only attribute of a table so...
0
1858
by: gustavo_randich | last post by:
Hello, I'm looking for a DB2 workaround on a topic already solved in Oracle: the problem of mutating tables (which states that a trigger action cannot read the triggering table's data). Yes, I know the trivial answer: "just pass the triggering table's data as parameters to the stored procedures called in the triggers, etc."; but it's a long story to tell why I can't. Below is the mentioned workaround's template I'm using for an UPDATE
4
3341
by: Jan | last post by:
Have an SQL create/import script. Running this on SQL would make it create a table with some values. Can Access2003 somehow use such and SQL script? I went into SQL query view to try it out, but the amount of data was too big to paste in according to Access. Sample data: -- -- PostgreSQL database dump
14
4415
by: Susan Rice | last post by:
I want to create a readonly array of data, then a readonly array of a structure. This is data I access but I want it protected against accidental change. The following is my test code. #include "stdafx.h" struct LVC { unsigned short int lo; unsigned short int hi;
4
4541
by: daqmaneng | last post by:
does anyone have any suggestions for writing a two dimensional array of data to a file. Currently, I have an array of 5 columns, with 1000 elements per array. I know that I can use a for next loop to go through each data point in the array and use the streamwriter class for each individual data point and write each point individually to the file. I would like to simplify this by simply writing the entire array to file.
3
2667
by: jonniethecodeprince | last post by:
Hi all, I have trouble getting an array of data stored in a separate javascript file i.e. a file called books.js into a table of data for a .xhtml file. There are 50 Records in this file. There are 5 colums of data I wish to display. I want to display these records in groups of 10. Based on the fact that the records I want are located in a separate file, how can I get these details to show on the form and manipulate the data to...
15
8451
by: Madhur | last post by:
Hi All, I would like you help me in creating an array of data types. I am interested in look at the the data type which looks like this Array a={int,float,char,int*..............................}, so that a should return me int and a should return me
5
10057
by: billelev | last post by:
I have a large array of data (1000 x 40 x 3) that I am inserting into a database table. It is incredibly slow, and so I was wondering if there is a quicker way of inserting array data into a table. Here is the code I am currently using: ' ,, With rs For nSec = 0 To UBound(vtData, 2) For ndate = 0 To UBound(vtData, 1) For nfield = 1 To UBound(vtData, 3)
1
4601
by: mbedford | last post by:
I've built a series of queries that bring together and process data from several different tables and queries and at the end a single query returns a single record based on a selection made in a form. I've built myself into a bit of a bind, however, in that the queries begin by referencing the value in a control in the form, and the form itself is based on the query. This circular setup is not working. Obviously. In order to better...
0
9564
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10548
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10295
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7604
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.