473,566 Members | 3,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.NET: syntax to insert value into an array

seshu
156 New Member
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 16707
Killer42
8,435 Recognized Expert Expert
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 Top Contributor
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 New Member
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 New Member
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 Top Contributor
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.Ex ecute(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("Name s").Value
rst.MoveNext
Next i
End If
End Sub

Private Sub Load_strNames_T o_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.Ex ecute strsql
Next i
End Sub

Private Sub Command1_Click( )
Load_strNames_T o_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 Top Contributor
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.Ex ecute(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("Name s").Value
rst.MoveNext
Next i
End If
End Sub

Private Sub Load_strNames_T o_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.Ex ecute strsql
Next i
End Sub

Private Sub Command1_Click( )
Load_strNames_T o_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 New Member
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
2064
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 on comp.programming, this may be off topic, but I've posted there because the critique was part of a discussion in that group.
24
22578
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 quotes? Do I need to use code to scrub each string and remove or escape the double quotes before using it in a query? The error I get is this: ...
5
2124
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: System.Runtime.InteropServices.COMException: Syntax error in INSERT INTO statement. Source Error: Line 118: MM_editCmd.ActiveConnection = MM_editConnection
2
6937
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 attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
1
5011
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=" & Server.MapPath("/db/VideoBlog.mdb") & ";" Set cmd = Server.CreateObject("ADODB.command") With cmd
2
2492
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 the array is an object itself but what is this syntax of the consecutive double quotes inside the brackets ?
0
3649
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 delegates were given CDs containing a pre-release version of the .NET framework/SDK and Visual Studio.NET. · When was the first version of .NET released?...
9
2451
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 through the application in Visual Studio .NET 2003 the application an exception when it executes the query.
1
1551
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 a structure (includes 3-dimensional array) to C++/CLI Dll, and the C++/CLI Dll will return a structure (includes 2- dimensional array) back to...
0
7903
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. ...
0
8115
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7650
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...
0
7959
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...
0
6272
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5488
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...
0
3648
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...
0
3630
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.