473,545 Members | 2,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need help with array in VB

I know my question seems easy,how to build an array to read the data from
Excel worksheet table then load the data into oracle.The table(employee)
looks like this have 4 columns:1-entity name with two
rows(employee,e mployee),2-entity/table
Definition(no rows),3-attribute name has 2
rows(employee_i d,employee_name ),4-Attribute/Column Definition with no rows.
My code is below:

Imports System.Data.Ole Db
Imports System.Data
Imports Oracle.DataAcce ss.Client

Public Class Form1

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim DS As System.Data.Dat aSet
Dim MyCommand As System.Data.Ole Db.OleDbDataAda pter
Dim MyConnection As System.Data.Ole Db.OleDbConnect ion

MyConnection = New System.Data.Ole Db.OleDbConnect ion( _
"provider=Micro soft.Jet.OLEDB. 4.0; " & _
"data source=C:\emplo yee.XLS; " & _
"Extended Properties=Exce l 8.0;")
' Select the data from Sheet1 of the workbook.
' Create OleDbCommand object and select data from worksheet Sheet1
MyCommand = New System.Data.Ole Db.OleDbDataAda pter( _
"select * from [Sheet1$]", MyConnection)

DS = New System.Data.Dat aSet()

' Fill the DataSet from the data extracted from the worksheet.
MyCommand.Fill( DS)
MyConnection.Cl ose()
Debug.Print(DS. Tables(0).Rows( 0).Item(0))
Debug.Print(DS. Tables(0).Rows( 0).Item(2))
Debug.Print(DS. Tables(0).Rows( 1).Item(0))
Debug.Print(DS. Tables(0).Rows( 1).Item(2))
'1.Create connection object to Oracle database
Dim con As OracleConnectio n = New OracleConnectio n()
Try
'2.Specify connection string
con.ConnectionS tring = ("Data Source=damn;Use r Id=gms;
Password=rts123 ")

'3. Open the connection through ODP.NET
con.Open()
Catch ex As Exception
'4.display if any error occurs
MsgBox(ex.Messa ge, Microsoft.Visua lBasic.MsgBoxSt yle.Exclamation ,
"OraScan")

'3.Create command object to perform a query against the database:

Dim cmdQuery As String = "SELECT * FROM employee"

' Create the OracleCommand object to work with select
Dim cmd As OracleCommand = New OracleCommand(c mdQuery)
cmd.Connection = con
cmd.CommandType = CommandType.Tex t

' Dispose OracleCommand object
cmd.Dispose()
Finally

' Close and Dispose OracleConnectio n object
con.Close()
con.Dispose()

End Try
End Sub
End Class


Jun 27 '08 #1
4 1016

"constantin " <co********@dis cussions.micros oft.comwrote in message
news:E0******** *************** ***********@mic rosoft.com...
>I know my question seems easy,how to build an array to read the data from
Excel worksheet table then load the data into oracle.The table(employee)
looks like this have 4 columns:1-entity name with two
rows(employee,e mployee),2-entity/table
Definition(no rows),3-attribute name has 2
rows(employee_i d,employee_name ),4-Attribute/Column Definition with no
rows.
My code is below:

Imports System.Data.Ole Db
Imports System.Data
Imports Oracle.DataAcce ss.Client

Public Class Form1

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim DS As System.Data.Dat aSet
Dim MyCommand As System.Data.Ole Db.OleDbDataAda pter
Dim MyConnection As System.Data.Ole Db.OleDbConnect ion

MyConnection = New System.Data.Ole Db.OleDbConnect ion( _
"provider=Micro soft.Jet.OLEDB. 4.0; " & _
"data source=C:\emplo yee.XLS; " & _
"Extended Properties=Exce l 8.0;")
' Select the data from Sheet1 of the workbook.
' Create OleDbCommand object and select data from worksheet Sheet1
MyCommand = New System.Data.Ole Db.OleDbDataAda pter( _
"select * from [Sheet1$]", MyConnection)

DS = New System.Data.Dat aSet()

' Fill the DataSet from the data extracted from the worksheet.
MyCommand.Fill( DS)
MyConnection.Cl ose()
Debug.Print(DS. Tables(0).Rows( 0).Item(0))
Debug.Print(DS. Tables(0).Rows( 0).Item(2))
Debug.Print(DS. Tables(0).Rows( 1).Item(0))
Debug.Print(DS. Tables(0).Rows( 1).Item(2))
'1.Create connection object to Oracle database
Dim con As OracleConnectio n = New OracleConnectio n()
Try
'2.Specify connection string
con.ConnectionS tring = ("Data Source=damn;Use r Id=gms;
Password=rts123 ")

'3. Open the connection through ODP.NET
con.Open()
Catch ex As Exception
'4.display if any error occurs
MsgBox(ex.Messa ge, Microsoft.Visua lBasic.MsgBoxSt yle.Exclamation ,
"OraScan")

'3.Create command object to perform a query against the database:

Dim cmdQuery As String = "SELECT * FROM employee"

' Create the OracleCommand object to work with select
Dim cmd As OracleCommand = New OracleCommand(c mdQuery)
cmd.Connection = con
cmd.CommandType = CommandType.Tex t

' Dispose OracleCommand object
cmd.Dispose()
Finally

' Close and Dispose OracleConnectio n object
con.Close()
con.Dispose()

End Try
End Sub
End Class

You should have an "array" after the MyCommand.Fill( DS). The problem I see
is your Oracle. You need to insert data not select it. Where exactly is
the problem?
LS

Jun 27 '08 #2
The problem is I need to read data from excel worksheet then load the data to
Oracle. It isn't doning so.plz refer to the first posting for excel worksheet
detail.
Thanks
Jun 27 '08 #3
"constantin " <co********@dis cussions.micros oft.comschrieb
The problem is I need to read data from excel worksheet then load
the data to Oracle. It isn't doning so.plz refer to the first
posting for excel worksheet detail.
Thanks
In your code, you don't write the data into the Oracle database. Do you
want to know how to do it or what is your question? As Lloyd wrote, you
need to execute an Insert SQL to write the data. However, only
changed/deleted/added rows in the dataset are written. It depends on the
Rowstate of the Datarows which is "unchanged" after reading fromt the
Excel file, no row is written even if you'd execute the Insert.
Armin

Jun 27 '08 #4
thanks I need to know how to write data to oracle using the information I
provided in my last email. Can someone correct my code.

Jun 27 '08 #5

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

Similar topics

9
2108
by: Nathan Rose | last post by:
Here's my problem. I am reading from a text file using this: if (!file_exists($file)) { echo "Don't exist\n"; return false; } $fd = @fopen($file, 'r'); if (!is_resource($fd))
4
5963
by: KellyH | last post by:
Hi, I hope someone can point me in the right direction. I'll get it out of the way: Yes, I am a college student. No, I am not looking for anyone to do my homework, just looking for help. I have been reading this ng all semester, and found it very helpful. I just have a stupid problem going on right now. Here's the project: We have to...
3
1930
by: Tommy Lang | last post by:
I am working on this project and I need some help/pointers/comments to get me started, I am stuck. The program will be used to store information in an array while it is running. I need to store objects of my classes Person(superclass), Student(inherit Person), Teacher(inherit Person) in that array. The name will be the unique key. These...
48
3198
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and "huge" Indy is both as a project, in support, development, and use. But Indy is new to the .net world. Indy is a HUGE library implementing over 120...
2
3351
by: Thomas Connolly | last post by:
Anyone know if there is a C# equivallent to: enum { LIFFE_SIZE_AUTOMARKETREF = 15 }; typedef char LiffeAutoMarketReference ; Thanks,
23
2510
by: vinod.bhavnani | last post by:
Hello all, I need desperate help Here is the problem: My problem today is with multidimensional arrays. Lets say i have an array A this is a 4 dimensional static array.
12
3858
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that looked sensible, but it didn't work right. Here is a simple example of what I'm trying to accomplish: // I have a hardware peripheral that I'm...
5
1184
by: SpreadTooThin | last post by:
If you are deriving a new class from another class, that you must (I assume) know the initializer of the other class. So in myClass import array class myClass(arrary.array): def __init__(self, now here I need to put array's constructor parameters..., then mine): array.array.__init__(self, typecode)
20
4610
by: Martin Jørgensen | last post by:
Hi, I'm reading a number of double values from a file. It's a 2D-array: 1 2 3 4 5 6 7 ------------- 1 3.2 2 0 2.1 3 9.3 4
1
2074
by: javabeginner123 | last post by:
i have a java prob, and i have to solve it fast, but i'm just getting to know it, so plz help me solve it with full code completed, thanks so much. the prob is to create a monter fight and there is the description: The monsters are of a very strange kind, called "Bigmon". They have some basic characteristics, like attack and defense power, life...
0
7428
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...
0
7941
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
7452
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
6014
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...
0
5071
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...
0
3467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
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
1
1039
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
738
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...

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.