Skip to Main Content

Oracle Developer Tools for Visual Studio

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Newbie needs help from the experts: Create simple Table in ODP.NET

152375Jul 22 2007 — edited Jul 30 2007
Can someone please help me? I'm trying to create a simple table in VB.NET using the ODP. I am a newbie in the .NET world and seem to be having a difficult time. All of the samples online ask that we use SQL PLUS for creating the table in Oracle, but I want to create it with a click of the button on the Form. Here is my code below:

Private Sub btnCreateTbl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateTbl.Click

' Open the connection
da.SelectCommand = New OracleCommand("DROP TABLE CARS", conn)
da.SelectCommand = New OracleCommand("CREATE TABLE CARS", "(carId INTEGER CONSTRAINT PKeycarId PRIMARY KEY," + "carBrand Char(10), Char(10), carCost Float)", conn)

Try
cmd.ExecuteNonQuery()
' Adding records the table
sql = "INSERT INTO CARS(carId, carBrand, carCost) " + "VALUES (1001, 'Ford', 'Taurus', 5523.98 ) "
cmd = New SqlCommand(sql, conn)
cmd.ExecuteNonQuery()
sql = "INSERT INTO CARS(carId, carBrand, carCost) " + "VALUES (1002, 'Chevy', 'Cavalier', 7353.64) "
cmd = New SqlCommand(sql, conn)
cmd.ExecuteNonQuery()
sql = "INSERT INTO CARS(carId, carBrand, carCost) " + "VALUES (1003, 'Mitsubishi', 'Eclipse', 8000.00) "
cmd = New SqlCommand(sql, conn)
cmd.ExecuteNonQuery()
sql = "INSERT INTO CARS(carId, carBrand, carCost) " + "VALUES (1004, 'Nissan', 'Maxima', 9999.00) "
cmd = New SqlCommand(sql, conn)
cmd.ExecuteNonQuery()
Catch ae As SqlException
MessageBox.Show(ae.Message.ToString())
End Try
End Sub 'CreateTableBtn_Click

End Class

Thanks in advance!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 27 2007
Added on Jul 22 2007
11 comments
2,736 views