I have next function
GetData("CasCadingDropDownList.spGETCOUNTRIES", "cur_countries",
new OracleParameter ("pContinentId", ddlContinents.SelectedValue));
pcontinentid is number
Defining GetData:
private DataSet GetData(string spName, string crsName, OracleParameter spParameter)
I add in source
cmd.Parameters.Add(spParameter).Direction = ParameterDirection.Input;
But my type of spParameter is wrong! How can i change this?
Loading
VulpesPosted Oct 7, 2014, 5:14 PM
The input parameter should be added first and the output parameter second.
andreas domevscekPosted Oct 7, 2014, 4:45 PM
I also have call to another procedure without parameter in program
This works, but when i do with parameter it crashes
procedure spGetCountries (pContinentId in number
,cur_countries out t_cursor)
is
begin
open cur_countries for select Countryid, CountryName from tblCountries where continentid = pContinentId;
end;
VulpesPosted Oct 7, 2014, 4:39 PM
We must be missing something here with the parameter types.
andreas domevscekPosted Oct 7, 2014, 4:29 PM
Still same error.
protected void ddlContinents_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlContinents.SelectedIndex == 0)
{
ddlCountries.SelectedIndex = 0;
ddlCountries.Enabled = false;
ddlCities.SelectedIndex = 0;
ddlCities.Enabled = false;
}
else
{
ddlCountries.Enabled = true;
decimal temp = Convert.ToDecimal(ddlContinents.SelectedValue);
ddlCountries.DataSource =
GetData("CasCadingDropDownList.spGETCOUNTRIES", "cur_countries",
new OracleParameter("pContinentId", new OracleDecimal(temp)));
ddlCountries.DataBind();
ListItem liCountry = new ListItem("Select country", "-1");
ddlCountries.Items.Insert(0, liCountry);
ddlCities.SelectedIndex = 0;
ddlCities.Enabled = false;
}
}
Then i have
private DataSet GetData(string spName, string crsName, OracleParameter spParameter)
{
string CS = ConfigurationManager.ConnectionStrings["OraAspNetConString"].ConnectionString;
using (OracleConnection con = new OracleConnection(CS))
{
OracleCommand cmd = new OracleCommand(spName, con);
cmd.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
OracleDataAdapter da = new OracleDataAdapter();
cmd.Parameters.Add(crsName, OracleDbType.RefCursor).Direction = ParameterDirection.Output;
if (spParameter != null)
{
cmd.Parameters.Add(spParameter).Direction = ParameterDirection.Input;
}
da.SelectCommand = cmd;
da.Fill(ds); AT THIS LINE OCCURS ERROR
return (ds);
}
}
VulpesPosted Oct 7, 2014, 4:04 PM
andreas domevscekPosted Oct 7, 2014, 3:16 PM
VulpesPosted Oct 7, 2014, 3:07 PM
So I'd try Convert.ToDecimal rather than Convert.ToInt32.
andreas domevscekPosted Oct 7, 2014, 2:06 PM
I Changed
new OracleParameter("pContinentId", Convert.ToInt32(ddlContinents.SelectedValue)))
but still doesn't work, same error
Perhaps error is in
if (spParameter != null)
{
cmd.Parameters.Add(spParameter).Direction = ParameterDirection.Input;
}
Wim SturkenboomPosted Oct 7, 2014, 2:16 AM
You can use one of the below
int i;
i = Convert.ToInt32(yourstring);
i = Int32.Parse(yourstring);
Int32.TryParse(yourstring, out i);
For the last one, you need to check the return value of the method to check if the parsing was successful. For the first two, you need a try/catch block to handle possible errors (in case the selected value is not an integer.