473,386 Members | 1,764 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,386 software developers and data experts.

SELECT query

6
hi
I am new to vb.net and i want to store the values for a selectcommand into a dynamic array.is it possible? i am using MS access
this is my code
Me.OleDbConnection1.Open()
Me.OleDbDataAdapter1.SelectCommand.CommandText = " SELECT age FROM sample where age>50"
Me.OleDbSelectCommand1.ExecuteNonQuery()
i want to store the result of selectcommand1 to get stored in an array

thanks
ramya
Mar 3 '07 #1
5 1143
use data Reader to read one by one and store in the array
Mar 3 '07 #2
ramyan
6
use data Reader to read one by one and store in the array
how to ?can u explain witha piece of code.sorry ..i am new to.net
Mar 3 '07 #3
vijaydiwakar
579 512MB
how to ?can u explain witha piece of code.sorry ..i am new to.net
wait for some time i'll give it to u
Mar 3 '07 #4
vijaydiwakar
579 512MB
hi
I am new to vb.net and i want to store the values for a selectcommand into a dynamic array.is it possible? i am using MS access
this is my code
Me.OleDbConnection1.Open()
Me.OleDbDataAdapter1.SelectCommand.CommandText = " SELECT age FROM sample where age>50"
Me.OleDbSelectCommand1.ExecuteNonQuery()
i want to store the result of selectcommand1 to get stored in an array

thanks
ramya
try this code
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         Dim Conn As New OleDb.OleDbConnection
  3.         Dim cmd As New OleDb.OleDbCommand
  4.         Dim Rdr As OleDb.OleDbDataReader
  5.         With Conn
  6.             .ConnectionString = "<thy connection string>"
  7.             .Open()
  8.             With cmd
  9.                 .CommandText = "SELECT age FROM sample where age>50"
  10.                 .CommandType = CommandType.Text
  11.                 Rdr = .ExecuteReader
  12.                 .Clone()
  13.                 .Dispose()
  14.             End With
  15.             .Close()
  16.             .Dispose()
  17.         End With
  18.         Dim myarr() As String
  19.         Dim i%
  20.         With Rdr
  21.             Do While .Read
  22.                 i += 1
  23.                 '<strore the item in thy array here 0th column value will be returned  as
  24.                 myarr(i) = .GetValue(0).ToString
  25.             Loop
  26.  
  27.         End With
  28.         'insted of using dynamic array u may use dataset as
  29.         Dim ds As New DataSet
  30.         Dim Adp As OleDb.OleDbDataAdapter
  31.         With Conn
  32.             .ConnectionString = "<thy connection string>"
  33.             .Open()
  34.             With cmd
  35.                 .CommandText = "SELECT age FROM sample where age>50"
  36.                 .CommandType = CommandType.Text
  37.                 Adp = New OleDb.OleDbDataAdapter(cmd)
  38.                 .Clone()
  39.                 .Dispose()
  40.             End With
  41.             .Close()
  42.             .Dispose()
  43.         End With
  44.         Adp.Fill(ds)
  45.         ' here all values will be stored in dataset
  46.     End Sub
  47.  
Mar 3 '07 #5
ramyan
6
Hi
Thanks a ton!i could work with dataset as u said.but i am getting run time error in array
Dim Rdr As OleDb.OleDbDataReader
OleDbConnection1.Open()
OleDbDataAdapter1.SelectCommand.CommandText = " SELECT age FROM sample where age>50"
Rdr = OleDbSelectCommand1.ExecuteReader
Dim myarr() As String
Dim i%
i = 1
While Rdr.Read
myarr(i) = Rdr.GetValue(0).ToString
i += 1
End While


note: if i give the size of array it works fine .else if its a dynamic array it gives an error Object reference not set to an instance of an object. but for this what you gave is fine .
Mar 3 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
1
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
2
by: Pavel Stehule | last post by:
Hello, Pg make query 1. and 2. very fast (use index), but for query 3. dont use index. I can solve its using select union, but I readed so pg 7.5 don't problem with OR operator. I use cvs pg. I...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
0
by: djflow | last post by:
Hi! II was wondering if you can help me with SQL query.. Below 7 separated select query works fine(only when they are retrieved separately) But I want to combined them together and so that i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.