473,406 Members | 2,549 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,406 software developers and data experts.

VB.NET: syntax to insert value into an array

seshu
156 100+
Hi everybody
This is seshu to explain more clearly about the above title i have a table in database now i want get a column from that table with all the rows for suppose the comlumn is containg the name i want send all those to an array in my fron end and after that on a button click i want to send all the names in array in to another table in my database i hope someone will help me atleast with giving input to array and retrive the data from array
thanking you
regards
seshu
Jan 12 '07 #1
7 16696
Killer42
8,435 Expert 8TB
Well, I haven't tested it, but I think this little self-contained routine will add a string to an array...
Expand|Select|Wrap|Line Numbers
  1. Public Sub AddStringToArray(ByVal strEntry As String, strArray() As String)
  2.   Dim Upper As Long, Lower As Long
  3.   Upper = UBound(strArray)
  4.   Lower = LBound(strArray)
  5.   ReDim Preserve strArray(Lower To Upper + 1)
  6.   strArray(Upper + 1) = strEntry
  7. End Sub
Note that the array must be defined in such a way that the size can be changed, for this to work. But anyway, even if you don't use the routine, the code should be useful as an example of adding to an array.
Jan 12 '07 #2
willakawill
1,646 1GB
Hi everybody
This is seshu to explain more clearly about the above title i have a table in database now i want get a column from that table with all the rows for suppose the comlumn is containg the name i want send all those to an array in my fron end and after that on a button click i want to send all the names in array in to another table in my database i hope someone will help me atleast with giving input to array and retrive the data from array
thanking you
regards
seshu
Is this an array or a recordset that you want? Do you want to return the data to your app so that you can access it, sort it etc or do you specifically want it to be transferred into an array?

A recordset object will hold the data and you can create an array from it if you really need to using the GetRows() method if you declare a variant.

Expand|Select|Wrap|Line Numbers
  1. Dim MyArray As Variant
  2.  
  3. MyArray = MyRecordset.GetRows()
Jan 12 '07 #3
seshu
156 100+
thanks to both of you and iam sorry for delaying in watching your sugesions ofcourse i dint check yet the moment i check this i will report you
thank you
regards
seshu
Jan 12 '07 #4
seshu
156 100+
sorry sir i dint find the way to impleement i mean i dint understand atall can you give me detail coding and one more thing i dont know how to asign this array to a column and the my application is in vb.net
Jan 12 '07 #5
hariharanmca
1,977 1GB
sorry sir i dint find the way to impleement i mean i dint understand atall can you give me detail coding and one more thing i dont know how to asign this array to a column and the my application is in vb.net

Dim strName() As String

Private Sub Load_dbNames_TO_Array()
Dim rst As ADODB.Recordset
Dim lngRecordCount As Long
Dim i As Long
strsql = "Select Names from Table1"
Set rst = dbConnection.Execute(strsql)
If rst.recordcount > 0 Then
lngRecordCount = rst.recordcount - 1
ReDim strName(0 To lngRecordCount) As String
For i = 0 To lngRecordCount
strName(i) = rst.field("Names").Value
rst.MoveNext
Next i
End If
End Sub

Private Sub Load_strNames_To_Database()
Dim rst As ADODB.Recordset
Dim lngArrayCount As Long
Dim i As Long
lngArrayCount = UBound(strName)
For i = 0 To lngArrayCount
strsql = "Insert into Table2 (Names) values('" & strName(i) & "')"
dbConnection.Execute strsql
Next i
End Sub

Private Sub Command1_Click()
Load_strNames_To_Database
End Sub

Private Sub Form_Load()
Load_dbNames_TO_Array
End Sub


I think this will solve you
Jan 12 '07 #6
willakawill
1,646 1GB
Dim strName() As String

Private Sub Load_dbNames_TO_Array()
Dim rst As ADODB.Recordset
Dim lngRecordCount As Long
Dim i As Long
strsql = "Select Names from Table1"
Set rst = dbConnection.Execute(strsql)
If rst.recordcount > 0 Then
lngRecordCount = rst.recordcount - 1
ReDim strName(0 To lngRecordCount) As String
For i = 0 To lngRecordCount
strName(i) = rst.field("Names").Value
rst.MoveNext
Next i
End If
End Sub

Private Sub Load_strNames_To_Database()
Dim rst As ADODB.Recordset
Dim lngArrayCount As Long
Dim i As Long
lngArrayCount = UBound(strName)
For i = 0 To lngArrayCount
strsql = "Insert into Table2 (Names) values('" & strName(i) & "')"
dbConnection.Execute strsql
Next i
End Sub

Private Sub Command1_Click()
Load_strNames_To_Database
End Sub

Private Sub Form_Load()
Load_dbNames_TO_Array
End Sub


I think this will solve you
This is not a good idea. Using the recordcount property will give different results depending on the recordset type, cursor type etc. You could have a million records and get -1 for the recordcount property as shown.

You are also limited here to a single column at a time. You can capture all of the columns of a table with GetRows()


Expand|Select|Wrap|Line Numbers
  1. Dim MyArray As Variant
  2.  
  3. If Not rs.EOF Then
  4.    MyArray = rs.GetRows()
  5. End If
Jan 12 '07 #7
seshu
156 100+
sir here at this place i dont have vb6 and i am strugling to convert the code into vb.net how is it in .net
regards
seshu
Jan 12 '07 #8

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

Similar topics

37
by: Eric | last post by:
There is a VB.NET critique on the following page: http://www.vb7-critique.741.com/ for those who are interested. Feel free to take a look and share your thoughts. Cheers, Eric. Ps: for those...
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
5
by: amitbadgi | last post by:
Hi guys, I am getting the following error in teh insert statement , I am converting this asp application to asp.net, here is teh error, Exception Details:...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
1
by: solomon_13000 | last post by:
connection.asp: <% Sub RunQueryString (pSQL,parms) on error resume next Set conn = Server.CreateObject("ADODB.Connection") conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &...
2
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of...
0
by: shamirza | last post by:
· When was .NET announced? Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on .NET technology, and...
9
by: Frawls | last post by:
Hi I Am am having problems with a stored Procedure that i wrote. Basically whats happening is that the Stored procedure Runs fine when i EXECUTE it in SQL Query analyzer. But when i debug...
1
by: lia.leon | last post by:
Can anyone give me a simple example to demonstrate the captioned question? Actually, instead of PInvoke, we'd like to utilize the united .Net platform to support our requirement:- VB.Net sends...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.