vmandem
asked on
How to call and execute an oracle stored Procedure from VB.NET
I have a stored procedure like this:
Procedure get_test
(i_C1 IN nm_D
,i_C2 IN nm_K
,i_param1 IN VARCHAR2
,i_param2 IN VARCHAR2
,o_curve OUT curvattype_1)
IS
lv_xp xp.xp_id
lv_end_dt DATE;
--Here I have all my BEGING,OPEN,SELECT statments
------
---
--
END get_test
My question is how to call this stored procedure from my VB.NET and execute it and also pass
the argument variables to the procedure like above o_curve i have to pass this value from
vb.net to the stored procedure. How to do this. Give me some examples.
Thanks
vm
Procedure get_test
(i_C1 IN nm_D
,i_C2 IN nm_K
,i_param1 IN VARCHAR2
,i_param2 IN VARCHAR2
,o_curve OUT curvattype_1)
IS
lv_xp xp.xp_id
lv_end_dt DATE;
--Here I have all my BEGING,OPEN,SELECT statments
------
---
--
END get_test
My question is how to call this stored procedure from my VB.NET and execute it and also pass
the argument variables to the procedure like above o_curve i have to pass this value from
vb.net to the stored procedure. How to do this. Give me some examples.
Thanks
vm
Dim constr As String
constr = "server=idnsql;integrated security=true;database=Ili ana"
Dim conn As New SqlClient.SqlConnection(co nstr)
Dim cmd As New SqlClient.SqlCommand("Owne rsSearch", conn)
Dim da As New SqlClient.SqlDataAdapter(c md)
Dim ds As New DataSet
Dim flag As Boolean
Try
flag = False
txtContact.Text = ""
cmd.CommandType = CommandType.StoredProcedur e
conn.Open()
constr = "server=idnsql;integrated security=true;database=Ili
Dim conn As New SqlClient.SqlConnection(co
Dim cmd As New SqlClient.SqlCommand("Owne
Dim da As New SqlClient.SqlDataAdapter(c
Dim ds As New DataSet
Dim flag As Boolean
Try
flag = False
txtContact.Text = ""
cmd.CommandType = CommandType.StoredProcedur
conn.Open()
In my example "OwnersSearch " is my stored procedure....
Then I add my parameters like:
cmd.Parameters.Add("@Conta ct", SqlDbType.Int)
cmd.Parameters("@Contact") .Value = CInt(txtContact.Text)
SqlDataAdapter1.SelectComm and = cmd
SqlDataAdapter1.Fill(DsVie wContacts)
My SqlDaaAdapter1 and DsviewContacts were created previously
Then I add my parameters like:
cmd.Parameters.Add("@Conta
cmd.Parameters("@Contact")
SqlDataAdapter1.SelectComm
SqlDataAdapter1.Fill(DsVie
My SqlDaaAdapter1 and DsviewContacts were created previously
ASKER
razo
Since I'm used to ADO, what is the Namespace that I have to use to
get the OLED.
I get "c" is not declared error
Thanks
vm
Since I'm used to ADO, what is the Namespace that I have to use to
get the OLED.
I get "c" is not declared error
Thanks
vm
Sorry, but neither razo or Ilianam method will work, you need the oracleclient not sqlclient nor oledb
Dim con As New system.data.oracleclient.o racleconne ction("you rconnectio nstring")
dim oda as new system.data.oracleclient.o raclecomma nd("yourst oredproced ure")
oda.commandtype = commandtype.storedprocedur e
etc..
Dim con As New system.data.oracleclient.o
dim oda as new system.data.oracleclient.o
oda.commandtype = commandtype.storedprocedur
etc..
Well, that's true but no matter what kind of adapter you are using the results are the same....
You have to create a connection, a comand, and execute the comand
oda.execNonquery()
You have to create a connection, a comand, and execute the comand
oda.execNonquery()
Ilianam, that's true aswell
ASKER
Ronal & Ilianam
I get this error when I run the application with Oracle Client
Wrong number of arguments in line1, column7.
I know it refers to line1 in stored procedure but column 7 is
parameter that I'm passing.
And also when I gave the stored procedure name I gave the package name also like this:
myCMD.CommandText = "DAT_Q_VIEW.get_test"
I don't know why it is causing this problem.
VM
I get this error when I run the application with Oracle Client
Wrong number of arguments in line1, column7.
I know it refers to line1 in stored procedure but column 7 is
parameter that I'm passing.
And also when I gave the stored procedure name I gave the package name also like this:
myCMD.CommandText = "DAT_Q_VIEW.get_test"
I don't know why it is causing this problem.
VM
Dim cmd As New oracleclient.oracleCommand "DAT_Q_VIE W.get_test ", your connection)
mycmd.CommandType = CommandType.StoredProcedur e
mycmd.CommandType = CommandType.StoredProcedur
ASKER
Ilianam
I passed all those statements untill I get to Catch x in the Try statment I get the Message box with error. Here is the code I did:
Dim myCMD As New OracleCommand
myCMD.Connection = Oraclecon
myCMD.CommandText = "DAT_Q_VIEW.get_demand_awa rd_list"
myCMD.CommandType = CommandType.StoredProcedur e
myCMD.Parameters.Add(New OracleParameter("i_ptcpt_c d", OracleType.Char)).Value = "AEMN"
myCMD.Parameters.Add(New OracleParameter("i_mkt_cd" , OracleType.Char)).Value = "L"
myCMD.Parameters.Add(New OracleParameter("i_user_id ", OracleType.Char)).Value = "ETEST"
myCMD.Parameters.Add(New OracleParameter("i_start_d t_gmt", OracleType.DateTime)).Valu e = strdate
myCMD.Parameters.Add(New OracleParameter("i_end_dt_ gmt", OracleType.DateTime)).Valu e = strdate1
myCMD.Parameters.Add(New OracleParameter("i_parm01_ num", OracleType.NVarChar)).Valu e = "DEC"
myCMD.Parameters.Add(New OracleParameter("i_param02 _txt", OracleType.NVarChar)).Valu e = "DEM"
myCMD.Parameters.Add(New OracleParameter("o_curvar_ dem_awd_li st", OracleType.Cursor)).Direct ion = ParameterDirection.Output
Dim MyDA As New OracleDataAdapter(myCMD)
Try
MyDA.Fill(Ds)
Catch x
MessageBox.Show(x.Message. ToString)
End Try
I GET PASSED ALL THE ABOVE AND IN THE TRY STATEMENT I READ
THE ERROR IN MSGBOX, I'M TRYING TO FILL THE DATASET AND POPULATE THE RESULTS ON TO THE GRID.
thanks
vm
I passed all those statements untill I get to Catch x in the Try statment I get the Message box with error. Here is the code I did:
Dim myCMD As New OracleCommand
myCMD.Connection = Oraclecon
myCMD.CommandText = "DAT_Q_VIEW.get_demand_awa
myCMD.CommandType = CommandType.StoredProcedur
myCMD.Parameters.Add(New OracleParameter("i_ptcpt_c
myCMD.Parameters.Add(New OracleParameter("i_mkt_cd"
myCMD.Parameters.Add(New OracleParameter("i_user_id
myCMD.Parameters.Add(New OracleParameter("i_start_d
myCMD.Parameters.Add(New OracleParameter("i_end_dt_
myCMD.Parameters.Add(New OracleParameter("i_parm01_
myCMD.Parameters.Add(New OracleParameter("i_param02
myCMD.Parameters.Add(New OracleParameter("o_curvar_
Dim MyDA As New OracleDataAdapter(myCMD)
Try
MyDA.Fill(Ds)
Catch x
MessageBox.Show(x.Message.
End Try
I GET PASSED ALL THE ABOVE AND IN THE TRY STATEMENT I READ
THE ERROR IN MSGBOX, I'M TRYING TO FILL THE DATASET AND POPULATE THE RESULTS ON TO THE GRID.
thanks
vm
mycmd.Parameters.Add(outpu t, SqlDbType.Int)
cmd.Parameters(output).Dir ection = ParameterDirection.Output
cmd.ExecuteNonQuery()
Also is the datagrid binded?
cmd.Parameters(output).Dir
cmd.ExecuteNonQuery()
Also is the datagrid binded?
ASKER
Illianam
I don't understand exactly what you stated there.
Do you want me to add this to the existing code or replace something. When I pasted this code in my app, i get
output is not declared
Yes my datagrid is binded like this:
DataGrid1.DataSource = Ds.Tables(0)
Please explain me what to do, I can increase the points though.
Thanks and appreciate your response.
vm
I don't understand exactly what you stated there.
Do you want me to add this to the existing code or replace something. When I pasted this code in my app, i get
output is not declared
Yes my datagrid is binded like this:
DataGrid1.DataSource = Ds.Tables(0)
Please explain me what to do, I can increase the points though.
Thanks and appreciate your response.
vm
You have this
myCMD.Parameters.Add(New OracleParameter("o_curvar_ dem_awd_li st", OracleType.Cursor)).Direct ion = ParameterDirection.Output
Isn't this a return value from the stored procedure?
myCMD.Parameters.Add(New OracleParameter("o_curvar_
Isn't this a return value from the stored procedure?
ASKER
Yes exactly that is a return value from the stored procedure. What
I don't understand from your previous comment that execute statement, I get the system.error when I come to that point.
I don't understand from your previous comment that execute statement, I get the system.error when I come to that point.
Look I have a function Insert data like this
I pass two arrays, the name of the parameter and the value
Try
cmd.CommandType = System.Data.CommandType.St oredProced ure
cmd.Connection = conn
conn.Open()
For i = 0 To UBound(param)
kind = param(i).GetType
cmd.Parameters.Add(param(i ), kind)
Next
For i = 0 To UBound(values)
cmd.Parameters(i).Value = values(i)
Next
cmd.Parameters.Add(output, SqlDbType.Int)
cmd.Parameters(output).Dir ection = ParameterDirection.Output
cmd.ExecuteNonQuery()
InsertData = cmd.Parameters(output).Val ue
Catch ex As Exception
DisplayError("Insert Data", ex)
End Try
I pass two arrays, the name of the parameter and the value
Try
cmd.CommandType = System.Data.CommandType.St
cmd.Connection = conn
conn.Open()
For i = 0 To UBound(param)
kind = param(i).GetType
cmd.Parameters.Add(param(i
Next
For i = 0 To UBound(values)
cmd.Parameters(i).Value = values(i)
Next
cmd.Parameters.Add(output,
cmd.Parameters(output).Dir
cmd.ExecuteNonQuery()
InsertData = cmd.Parameters(output).Val
Catch ex As Exception
DisplayError("Insert Data", ex)
End Try
ASKER
Ilianam
Well, now I think I have real problem here:
looking at my previous code that I pasted, Since I'm new to both .NET and stored Procedures I do not know excatly how to use the cursor for out put.
Do I have to replace the last cursorstatment with yours. I tried but still I get system.error. Do I have to declare the output.
Thanks
vm
Well, now I think I have real problem here:
looking at my previous code that I pasted, Since I'm new to both .NET and stored Procedures I do not know excatly how to use the cursor for out put.
Do I have to replace the last cursorstatment with yours. I tried but still I get system.error. Do I have to declare the output.
Thanks
vm
why you need a return value? You have to declare your output in your store procedure
ALTER PROCEDURE [dbo].InsertnHotels
@hotel_code varchar(5),
@hotel_name varchar(50),
@hotel_address varchar(75),
@hotel_city varchar(30),
@hotel_state char(2),
@hotel_zip varchar(10),
@hotel_phone varchar(15),
@hotel_directions ntext,
@hotel_map_link varchar(1000),
@hotel_id int OUTPUT
ALTER PROCEDURE [dbo].InsertnHotels
@hotel_code varchar(5),
@hotel_name varchar(50),
@hotel_address varchar(75),
@hotel_city varchar(30),
@hotel_state char(2),
@hotel_zip varchar(10),
@hotel_phone varchar(15),
@hotel_directions ntext,
@hotel_map_link varchar(1000),
@hotel_id int OUTPUT
ASKER
Ilianam
I got this code and when i execute I get input string is not formatted,
I checked the datatypes and everything still I get the error:
temp1 = "test"
temp2 = "hello"
temp3 = "34833"
temp4 = "DEC"
temp5 = "DEM"
Oraclecon.Open()
Dim myCMD As New OracleCommand
myCMD.Connection = Oraclecon
myCMD.CommandText = "DAT_TEST_VIEW.get_demand_ test_list"
myCMD.CommandType = System.Data.CommandType.St oredProced ure
myCMD.Parameters.Add(New OracleParameter("i_ptcpt_c d", OracleType.Char)).Value = "'& temp1 &'"
myCMD.Parameters.Add(New OracleParameter("i_mkt_cd" , OracleType.Char)).Value = "'& temp2 &'"
myCMD.Parameters.Add(New OracleParameter("i_user_id ", OracleType.Number)).Value = "34833"
myCMD.Parameters.Add(New OracleParameter("i_start_d t_gmt", OracleType.DateTime)).Valu e = "'& strdate &'"
myCMD.Parameters.Add(New OracleParameter("i_end_dt_ gmt", OracleType.DateTime)).Valu e = "'& strdate1 &'"
myCMD.Parameters.Add(New OracleParameter("i_parm01_ num", OracleType.Char)).Value = "'& temp4 &'"
myCMD.Parameters.Add(New OracleParameter("i_param02 _txt", OracleType.Char)).Value = "'& temp5 &'"
myCMD.Parameters.Add(New OracleParameter("o_curvar_ dem_awd_li st", OracleType.Cursor)).Direct ion = ParameterDirection.Output
myCMD.ExecuteNonQuery()
Thanks
vm
I got this code and when i execute I get input string is not formatted,
I checked the datatypes and everything still I get the error:
temp1 = "test"
temp2 = "hello"
temp3 = "34833"
temp4 = "DEC"
temp5 = "DEM"
Oraclecon.Open()
Dim myCMD As New OracleCommand
myCMD.Connection = Oraclecon
myCMD.CommandText = "DAT_TEST_VIEW.get_demand_
myCMD.CommandType = System.Data.CommandType.St
myCMD.Parameters.Add(New OracleParameter("i_ptcpt_c
myCMD.Parameters.Add(New OracleParameter("i_mkt_cd"
myCMD.Parameters.Add(New OracleParameter("i_user_id
myCMD.Parameters.Add(New OracleParameter("i_start_d
myCMD.Parameters.Add(New OracleParameter("i_end_dt_
myCMD.Parameters.Add(New OracleParameter("i_parm01_
myCMD.Parameters.Add(New OracleParameter("i_param02
myCMD.Parameters.Add(New OracleParameter("o_curvar_
myCMD.ExecuteNonQuery()
Thanks
vm
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dim Oraclecon As New OracleConnection("Server=n test;Uid=d ag;Pwd=dah ")
Is there anything I have to format the date because I get an error also not valid datemonth at index 3.
I formatted like this: "08-Sep-2004" which oracle accepts but I don't know is it passing like a string or something else.
Thanks
vm
Is there anything I have to format the date because I get an error also not valid datemonth at index 3.
I formatted like this: "08-Sep-2004" which oracle accepts but I don't know is it passing like a string or something else.
Thanks
vm
vmandem....
Please test yous sp in query analyzer and let me know
Please test yous sp in query analyzer and let me know
Dim c As New OleDb.OleDbCommand()
c.connection=conn
c.commandtext="procedurena
c.CommandType = CommandType.StoredProcedur
c.Parameters.Add(paramtern
c.Parameters(parametername
c.Parameters.Add(paramtern
c.Parameters(parametername
c.Parameters(paramtername)
c.ExecuteNonQuery()
dim s as string= c.Parameters(paramtername1