Oracle Stored Procedure unable to call from ASP.NET - asp.net

I have written a code in ASP.NET to fetch data from Oracle stored procedure. But I get an error when trying to fetch the data:
ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'USER_FEEDBACK' ORA-06550: line 1, column 7: PL/SQL: Statement ignored
Procedure code is this:
create or replace PROCEDURE user_feedback(cv_results out sys_refcursor,start_date IN VARCHAR2)
IS
BEGIN
open cv_results for
select pi.first_name || ' ' || pi.last_name initiator
......
from request_workflow w inner join request_workflow_attribute waRating
on waRating.request_workflow_id = w.row_id
and waRating.attr_name = 'UserRating'
.............
where w.date_stamp_utc between start_date and '31-dec-2015'
order by waRating.attr_value desc, eform_name;
END ;
This is my ASP.NET code:
Oracle.DataAccess.Client.OracleCommand objCmd = new Oracle.DataAccess.Client.OracleCommand();
objCmd.Connection = objConn;
objCmd.CommandText = "user_feedback";
objCmd.CommandType = CommandType.StoredProcedure;
Oracle.DataAccess.Client.OracleParameter oraP = new Oracle.DataAccess.Client.OracleParameter();
// System.Data.OracleClient.OracleParameter op = null;
oraP.OracleDbType = OracleDbType.RefCursor;
oraP.ParameterName = "cv_results";
oraP.Direction = System.Data.ParameterDirection.Output;
oraP.ParameterName = "start_date";
oraP.OracleDbType = OracleDbType.Varchar2;
oraP.Value = "01-Dec-2015";
oraP.Direction = System.Data.ParameterDirection.Input;
objCmd.Parameters.Add(oraP);
objConn.Open();
objCmd.ExecuteReader();
objCmd.ExecuteNonQuery();
Please suggest how to make it work.

You're only creating/adding a single parameter but assigning it twice with different values resulting in just one parameter to the call.
Instead, create and add two separate parameters, something like;
var oraP1 = new Oracle.DataAccess.Client.OracleParameter();
oraP1.OracleDbType = OracleDbType.RefCursor;
oraP1.ParameterName = "cv_results";
oraP1.Direction = System.Data.ParameterDirection.Output;
objCmd.Parameters.Add(oraP1);
var oraP2 = new Oracle.DataAccess.Client.OracleParameter();
oraP2.ParameterName = "start_date";
oraP2.OracleDbType = OracleDbType.Varchar2;
oraP2.Value = "01-Dec-2015";
oraP2.Direction = System.Data.ParameterDirection.Input;
objCmd.Parameters.Add(oraP2);

It's probably because you don't Add the first parameter. Try something like this?
...
oraP.ParameterName = "cv_results";
oraP.Direction = System.Data.ParameterDirection.Output;
objCmd.Parameters.Add(oraP);
oraP = new Oracle.DataAccess.Client.OracleParameter();
oraP.ParameterName = "start_date";
...
Though, it'd be better to declare another variable for the first param if you'll be reading from that refcursor later.

Related

Update query with multiple where conditions

I am trying to update the row. Here I have multiple where conditions. This is the query I have tried.
$this->createQueryBuilder("jv")
->update()
->set("jv.pictureStatus", "?1")
->set("jv.pictureStatusId", "?2")
->andWhere("jv.aa = ?3")
->andWhere("jv.bb = ?4")
->andWhere("jv.cc = ?5")
->andWhere("jv.dd = ?6")
->andWhere("jv.ee = ?7")
->andWhere("jv.ff = ?8")
->andWhere("jv.gg = ?9")
->setParameter(1, "100")
->setParameter(2, "200")
->setParameter(3, $wheres["aa"])
->setParameter(4, $wheres["bb"])
->setParameter(5, $wheres["cc"])
->setParameter(6, $wheres["dd"])
->setParameter(7, $wheres["ee"])
->setParameter(8, $wheres["ff"])
->setParameter(9, $wheres["gg"])
->getQuery()->execute();
When I execute this query it returns 0 but nothing is getting updated.

Encountered "ORA-01745: invalid host/bind variable name" when using DbDataAdapter.Update() with ODP.NET

I have a table defined in oracle 11g with below statement:
CREATE TABLE "TESTUSER"."TestTableOracleWriter"
("name" VARCHAR2(100 BYTE),
"group" VARCHAR2(100 BYTE),
"number" NUMBER(*,0),
"creation" DATE,
"sliceidentifier" RAW(100),
CONSTRAINT "TESTTABLEORACLEWRITER_PK" PRIMARY KEY ("name"))
And I am using the following code snippet to update the table with content in the dataTable:
private void BatchInsert(DbConnection connection, DbTransaction transaction, DataTable dataTable, string tableName)
{
DbDataAdapter adapter = ProviderFactories.GetFactory("Oracle.DataAccess.Client").CreateDataAdapter();
DbCommand insertCommand = connection.CreateCommand();
DbParameter parameter1 = insertCommand.CreateParameter();
parameter.DbType = DbType.String;
parameter.ParameterName = "#name";
parameter.SourceColumn = "name";
insertCommand.Parameters.Add(parameter);
DbParameter parameter2 = insertCommand.CreateParameter();
parameter2.DbType = DbType.String;
parameter2.ParameterName = "#group";
parameter2.SourceColumn = "group";
insertCommand.Parameters.Add(parameter2);
DbParameter parameter3 = insertCommand.CreateParameter();
parameter3.DbType = DbType.Int32;
parameter3.ParameterName = "#number";
parameter3.SourceColumn = "number";
insertCommand.Parameters.Add(parameter3);
DbParameter parameter4 = insertCommand.CreateParameter();
parameter4.DbType = DbType.DateTime;
parameter4.ParameterName = "#creation";
parameter4.SourceColumn = "creation";
insertCommand.Parameters.Add(parameter4);
insertCommand.CommandType = CommandType.Text;
insertCommand.CommandText = "INSERT INTO \"TestTableOracleWriter\" (\"name\", \"group\", \"number\", \"creation\") VALUES (:name, :group, :number, :creation)";
insertCommand.Transaction = transaction;
insertCommand.UpdatedRowSource = UpdateRowSource.None;
adapter.InsertCommand = insertCommand;
adapter.UpdateBatchSize = 0;
adapter.Update(dataTable);
}
But sometimes the code will fail with "ORA-01745: invalid host/bind variable name", I've searched on the internet and found some materials saying it has something to do with the oracle reserve word. From the link, "name", "group" and "number" is marked as reserve word. I can change my table column names to make the code work.
But the strangest thing is that the code does not fail all the time, it only fails when dataTable cotains only one row, in other scenarios, it works as expected. Anyone has ideas about that?
You can not use key word as parameter name.
Don't use group and number as parameter name

adding a chart control to a placeholder ASP.net VB

I'm trying to add a manually created chart to a placeholder but when i look at the output all i get is a blank.. I am getting the data from a dataset datatable that is the last table in the dataset. I only has two colums "Industry" and "industryTheta" any help is much appreciated. I'm not sure whats wrong here
Dim chrt As New Chart
chrt.ID = "dynChart"
chrt.Height = Unit.Pixel(1000)
chrt.Width = Unit.Pixel(1000)
chrt.BackImageWrapMode = ChartImageWrapMode.Scaled
chrt.BorderlineColor = Color.Black
chrt.ImageLocation = "~/TempImages/ChartPic_#SEQ(300,3)"
chrt.BackGradientStyle = GradientStyle.None
Dim ca As New ChartArea
ca.Name = "IndustryTheta"
ca.AlignmentOrientation = AreaAlignmentOrientations.All
ca.AlignmentStyle = AreaAlignmentStyles.All
ca.Area3DStyle.Enable3D = True
ca.Area3DStyle.LightStyle = LightStyle.Realistic
ca.Area3DStyle.Inclination = 30
ca.BackHatchStyle = ChartHatchStyle.None
chrt.ChartAreas.Add(ca)
Dim sers As New Series
sers.Name = "IndustryName"
sers.ChartType = SeriesChartType.Pie
sers.Label = "#VALX, #PERCENT"
sers.LabelAngle = 90
sers.IsXValueIndexed = True
sers.IsValueShownAsLabel = True
sers.XAxisType = AxisType.Primary
sers.YAxisType = AxisType.Primary
sers.YValuesPerPoint = 1
sers.XValueMember = "Industry"
sers.YValueMembers = "IndustryTheta"
chrt.Series.Add(sers)
For Each dr As DataRow In table.Rows
Dim p As New DataPoint
p.SetValueY(Convert.ToInt32(dr.Item("IndustryTheta")))
p.AxisLabel = dr.Item("Industry")
sers.Points.Add(p)
Next
chrt.DataBind()
dynamicGrids.Controls.Add(chrt)
Most likely your problem is with when you are calling your function in the page life cycle. Please refer to this information to learn more about it.
In order to address dynamic controls in asp.net please refer to this for more information on dynamic controls.

How to pass concatenated value of drop down to stored proc as parameter

I have a drop down where in the values are concatenated from two columns of a table, now I will use the value of that drop down as a parameter to another stored procedure, is this possible? How will I do that?
This is my code
CREATE PROCEDURE [dbo].[Reassign]
#recordumber int
#employeeName
AS
BEGIN
UPDATE QR
SET QR.QAMemberID = #QAMemberID
FROM Roster AS QR
INNER JOIN TeamMaster S TM
ON QR.QAMemberID = TM.QAMemberID
WHERE QR.recordNumber = #recordumber
and qr.firstname, qr.lastname = #employeeName
END
and qr.firstname, qr.lastname = #employeeName I know this last piece of code is wrong... how can I do this the right way? Thank you...
Do not concatenate the values together in your code, but rather use a parameter for firstName and a parameter for lastName, like this:
CREATE PROCEDURE [dbo].[Reassign]
#recordumber int,
#firstName,
#lastName
AS
BEGIN
UPDATE QR
SET QR.QAMemberID = #QAMemberID
FROM Roster AS QR
INNER JOIN TeamMaster S TM
ON QR.QAMemberID = TM.QAMemberID
WHERE QR.recordNumber = #recordumber
and qr.firstname = #firstName, qr.lastname = #lastName
END
To use the value from your drop down you can use this in the code behind
if (myDropDown.SelectedIndex != 0)
{
var myData = myDropDown.SelectedValue;
// access Sproc and you can then pass myData
}
You can use qr.firstname + ' ' + qr.lastname = #employeeName if you concatenated that fields with space.
...
and qr.firstname + ' ' + qr.lastname = #employeeName
...
But it's better to pass two parameters into the procedure:
CREATE PROCEDURE [dbo].[Reassign]
#recordumber int
#firstname,
#lastname
AS
...
and qr.firstname = #firstname and qr.lastname = #lastname
...

Getting error while inserting table in database?

i am inserting table in database using table datatype with the following code:
CREATE TYPE BackUpDoctorLocationAreaRoom AS TABLE (
[RoomId] bigint,
[AreaId] bigint,
[LocationId] bigint
);
Alter proc proc_tblBackUpDoctorInsert
(
#Id uniqueidentifier='',
#BackUpDoctorId uniqueidentifier='1323e1f4-7a93-4b45-9a9b-3840c32fd6d8',
#StartDate datetime='11/08/2012',
#EndDate datetime='11/09/2012',
#StartTime datetime='22:22:22',
#EndTime datetime='01:11:11',
#CreatedBy uniqueidentifier='acf7961c-4111-49ad-a66a-ce7f9ce131bd',
#ModifiedBy uniqueidentifier='acf7961c-4111-49ad-a66a-ce7f9ce131bd',
#createdDate datetime='11/6/12 3:09:58 AM',
#ModifiedDate datetime='11/6/12 3:09:58 AM',
#tblBackUpDoctorsForRooms BackUpDoctorLocationAreaRoom READONLY
)
as
set xact_abort on
declare #newId uniqueidentifier;
set #newId = newid();
insert into tblBackUpDoctor (Id,BackUpDoctorId,StartDate,EndDate,StartTime,EndTime,CreatedBy,ModifiedBy,
createdDate,ModifiedDate,IsActive,isdeleted) values
(#newId,
#BackUpDoctorId,
#StartDate,
#EndDate,
#StartTime,
#EndTime,
#CreatedBy,
#ModifiedBy,
#createdDate,
#ModifiedDate,
1,0)
declare #IdFortblBackUpDoctorsForRooms uniqueidentifier;
set #IdFortblBackUpDoctorsForRooms = newid();
delete from tblBackUpDoctorsForRooms where BackUpRecordId=#id and Roomid in (Select roomid from #tblBackUpDoctorsForRooms)
delete from tblbackupdoctor where id=#id
insert into tblBackUpDoctorsForRooms (BackUpRecordId,Roomid,Araeid,locationid)
Select #newId,roomid,areaid,locationid from #tblBackUpDoctorsForRooms
select #newId
This is the sp in which i am using that table.
My class file's code is :
public string InsertBackUpDoctor(ClsBackUpDoctorProp objProp, DataTable dtLocAreaRoom)
{
String ConnectionString = CCMMUtility.GetCacheForWholeApplication();
String backUpRecordId = "";
SqlParameter[] param = new SqlParameter[12];
param[0] = new SqlParameter("#Id", objProp.Id);
param[1] = new SqlParameter("#BackUpDoctorId", objProp.BackUpDoctorId);
param[2] = new SqlParameter("#StartDate", objProp.StartDate);
param[3] = new SqlParameter("#EndDate", objProp.EndDate);
param[4] = new SqlParameter("#StartTime", objProp.StartTime);
param[5] = new SqlParameter("#EndTime", objProp.EndTime);
param[6] = new SqlParameter("#CreatedBy", objProp.CreatedBy);
param[7] = new SqlParameter("#ModifiedBy", objProp.ModifiedBy);
param[8] = new SqlParameter("#createdDate", CCMMUtility.GetCurrentDateTimeByTimeZone("US Mountain Standard Time"));
param[9] = new SqlParameter("#ModifiedDate", CCMMUtility.GetCurrentDateTimeByTimeZone("US Mountain Standard Time"));
param[10] = new SqlParameter("#CurrentDate", objProp.CurrentDate);
param[11] = new SqlParameter("#tblBackUpDoctorsForRooms ", dtLocAreaRoom);
backUpRecordId = SqlHelper.ExecuteScalar(ConnectionString, "proc_tblbackupdoctorInsertBackUpDoctors", param).ToString();
return backUpRecordId;
}
and here is the error which is coming when i tries to insert :
The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Table-valued parameter 12 ("#tblBackUpDoctorsForRooms"), row 0, column 0: Data type 0xF3 (user-defined table type) has a non-zero length database name specified. Database name is not allowed with a table-valued parameter, only schema name and type name are valid.
I dont know why this coming please help me..
I believe you'd have to change the way you pass your custom parameter:
Not just
param[11] = new SqlParameter("#tblBackUpDoctorsForRooms ", dtLocAreaRoom);
but rather something like
SqlParameter parameter = new SqlParameter();
parameter.ParameterName = "#tblBackUpDoctorsForRooms";
parameter.SqlDbType = System.Data.SqlDbType.Structured;
parameter.TypeName = "BackUpDoctorLocationAreaRoom";
parameter.Value = dtLocAreaRoom;
param[11] = parameter;
try
parameter.SqlDbType = System.Data.SqlDbType.Structured;
parameter.TypeName = "BackUpDoctorLocationAreaRoom";
and in the call add
backUpRecordId = SqlHelper.ExecuteScalar(ConnectionString,CommandType.StoredProcedure
"proc_tblbackupdoctorInsertBackUpDoctors", param).ToString();

Resources