I have three stored procedures that I can use to retrieve data from Sybase database. Two of these three stored procedures have output parameters. These two stored procedures do not process and return values in the output parameters. The code for the stored procedure that executes properly by returning values in a datareader is as follows:
cmd = new OdbcCommand();
cmd.Connection = conn;
cmd.CommandText = "crdsp_get_pat_incr_srch_r ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?";
cmd.CommandType = CommandType.StoredProcedure;
OdbcParameter _patnamelast = new OdbcParameter();
_patnamelast.ParameterName = "@pat_name_last";
_patnamelast.OdbcType = OdbcType.VarChar;
_patnamelast.Size = 40;
_patnamelast.Direction = ParameterDirection.Input;
_patnamelast.Value = _LastName;
cmd.Parameters.Add(_patnamelast);
OdbcParameter _patnamefirst = new OdbcParameter();
_patnamefirst.ParameterName = "@pat_name_first";
_patnamefirst.OdbcType = OdbcType.VarChar;
_patnamefirst.Size = 20;
_patnamefirst.Direction = ParameterDirection.Input;
_patnamefirst.Value = _FirstName;
cmd.Parameters.Add(_patnamefirst);
OdbcParameter _patnamelastsearch = new OdbcParameter();
_patnamelastsearch.ParameterName = "@pat_name_last_srch_type";
_patnamelastsearch.OdbcType = OdbcType.VarChar;
_patnamelastsearch.Size = 11;
_patnamelastsearch.Direction = ParameterDirection.Input;
if (_ExactLastName)
{
_patnamelastsearch.Value = "Exact";
}
else if (!_ExactLastName)
{
_patnamelastsearch.Value = "Incremental";
}
cmd.Parameters.Add(_patnamelastsearch);
OdbcParameter _firstnamesearchtype = new OdbcParameter();
_firstnamesearchtype.ParameterName = "@first_name_srch_type";
_firstnamesearchtype.OdbcType = OdbcType.VarChar;
_firstnamesearchtype.Size = 11;
_firstnamesearchtype.Direction = ParameterDirection.Input;
_firstnamesearchtype.IsNullable = true;
if (_FirstName != "" && _FirstName != null)
{
if (_ExactFirstName)
{
_firstnamesearchtype.Value = "Exact";
}
else if (!_ExactFirstName)
{
_firstnamesearchtype.Value = "Incremental";
}
}
else if (!(_FirstName != "" && _FirstName != null))
{
_firstnamesearchtype.Value = DBNull.Value;
}
cmd.Parameters.Add(_firstnamesearchtype);
OdbcParameter _rowcount = new OdbcParameter();
_rowcount.ParameterName = "@row_count";
_rowcount.OdbcType = OdbcType.SmallInt;
_rowcount.Direction = ParameterDirection.Input;
_rowcount.Value = 0;
cmd.Parameters.Add(_rowcount);
OdbcParameter _patnamemid = new OdbcParameter();
_patnamemid.ParameterName = "@pat_name_mid";
_patnamemid.OdbcType = OdbcType.VarChar;
_patnamemid.Size = 20;
_patnamemid.Direction = ParameterDirection.Input;
_patnamemid.IsNullable = true;
_patnamemid.Value = DBNull.Value;
cmd.Parameters.Add(_patnamemid);
OdbcParameter _patgendercode = new OdbcParameter();
_patgendercode.ParameterName = "@pat_gender_code";
_patgendercode.OdbcType = OdbcType.Char;
_patgendercode.Size = 1;
_patgendercode.Direction = ParameterDirection.Input;
_patgendercode.IsNullable = true;
if (_Gender == null)
{
_patgendercode.Value = DBNull.Value;
}
else if (_Gender.ToUpper() == "F" || _Gender.ToUpper() == "FEMALE")
{
_patgendercode.Value = "F";
}
else if (_Gender.ToUpper() == "M" || _Gender.ToUpper() == "MALE")
{
_patgendercode.Value = "M";
}
cmd.Parameters.Add(_patgendercode);
OdbcParameter _birthmonth = new OdbcParameter();
_birthmonth.ParameterName = "@birth_month";
_birthmonth.OdbcType = OdbcType.TinyInt;
_birthmonth.Direction = ParameterDirection.Input;
_birthmonth.IsNullable = true;
_birthmonth.Value = DBNull.Value;
cmd.Parameters.Add(_birthmonth);
OdbcParameter _birthday = new OdbcParameter();
_birthday.ParameterName = "@birth_day";
_birthday.OdbcType = OdbcType.SmallInt;
_birthday.Direction = ParameterDirection.Input;
_birthday.IsNullable = true;
_birthday.Value = DBNull.Value;
cmd.Parameters.Add(_birthday);
OdbcParameter _birthyear = new OdbcParameter();
_birthyear.ParameterName = "@birth_year";
_birthyear.OdbcType = OdbcType.VarChar;
_birthyear.Direction = ParameterDirection.Input;
_birthyear.IsNullable = true;
_birthyear.Value = DBNull.Value;
cmd.Parameters.Add(_birthyear);
OdbcParameter _pataddrst = new OdbcParameter();
_pataddrst.ParameterName = "@pat_addr_st";
_pataddrst.OdbcType = OdbcType.Char;
_pataddrst.Size = 2;
_pataddrst.Direction = ParameterDirection.Input;
_pataddrst.IsNullable = true;
_pataddrst.Value = DBNull.Value;
cmd.Parameters.Add(_pataddrst);
OdbcParameter _pataddrpstcode = new OdbcParameter();
_pataddrpstcode.ParameterName = "@pat_addr_pst_code";
_pataddrpstcode.OdbcType = OdbcType.VarChar;
_pataddrpstcode.Size = 15;
_pataddrpstcode.Direction = ParameterDirection.Input;
_pataddrpstcode.IsNullable = true;
_pataddrpstcode.Value = DBNull.Value;
cmd.Parameters.Add(_pataddrpstcode);
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (dr.HasRows)
{
while (dr.Read())
{
Patient _Patient = new Patient();
_Patient.LastName = dr["pat_name_last"].ToString();
PatientList.Add(_Patient);
}
}
And some code for one of the other two procedures that have output parameters is as follows:
cmdx = new OdbcCommand();
cmdx.Connection = conn;
cmdx.CommandText = "crdsp_prov_nbr_convert ?, ?, ?, ?, ?, ?, ?, ?";
cmdx.CommandType = CommandType.StoredProcedure;
OdbcParameter _providnbr = new OdbcParameter();
_providnbr.ParameterName = "@prov_id_nbr";
_providnbr.OdbcType = OdbcType.Int;
_providnbr.Direction = ParameterDirection.Input;
_providnbr.IsNullable = true;
_providnbr.Value = _ProviderID;
cmdx.Parameters.Add(_providnbr);
OdbcParameter _provmbrnbr = new OdbcParameter();
_provmbrnbr.ParameterName = "@prov_mbr_nbr";
_provmbrnbr.OdbcType = OdbcType.Char;
_provmbrnbr.Size = 15;
_provmbrnbr.Direction = ParameterDirection.Input;
_provmbrnbr.IsNullable = true;
_provmbrnbr.Value = DBNull.Value;
cmdx.Parameters.Add(_provmbrnbr);
OdbcParameter _grpcode = new OdbcParameter();
_grpcode.ParameterName = "@grp_code";
_grpcode.OdbcType = OdbcType.Char;
_grpcode.Size = 8;
_grpcode.Direction = ParameterDirection.Input;
_grpcode.IsNullable = true;
if (_ProviderID != "" && _ProviderID != null)
{
_grpcode.Value = DBNull.Value;
}
else
{
_grpcode.Value = "LANID";
}
cmdx.Parameters.Add(_grpcode);
OdbcParameter _dgrpcode = new OdbcParameter();
_dgrpcode.ParameterName = "@d_grp_code";
_dgrpcode.OdbcType = OdbcType.Char;
_dgrpcode.Size = 8;
_dgrpcode.Direction = ParameterDirection.Input;
_dgrpcode.Value = "mc";
cmdx.Parameters.Add(_dgrpcode);
OdbcParameter _datein = new OdbcParameter();
_datein.ParameterName = "@date_in";
_datein.OdbcType = OdbcType.SmallDateTime;
_datein.Direction = ParameterDirection.Input;
_datein.Value = DateTime.Now.AddMonths(-1);
cmdx.Parameters.Add(_datein);
OdbcParameter _provmbrnbrout = new OdbcParameter();
_provmbrnbrout.ParameterName = "@prov_mbr_nbr_out";
_provmbrnbrout.OdbcType = OdbcType.VarChar;
_provmbrnbrout.Size = 15;
_provmbrnbrout.Direction = ParameterDirection.Output;
cmdx.Parameters.Add(_provmbrnbrout);
OdbcParameter _providnbrout = new OdbcParameter();
_providnbrout.ParameterName = "@prov_id_nbr_out";
_providnbrout.OdbcType = OdbcType.Int;
_providnbrout.Direction = ParameterDirection.Output;
cmdx.Parameters.Add(_providnbrout);
OdbcParameter _returncode = new OdbcParameter();
_returncode.ParameterName = "@return_code";
_returncode.OdbcType = OdbcType.Char;
_returncode.Size = 2;
_returncode.Direction = ParameterDirection.Output;
cmdx.Parameters.Add(_returncode);
_clinicno += "; just before execute; ";
cmdx.ExecuteNonQuery();
_clinicno += cmdx.Parameters["@prov_mbr_nbr_out"].Value.ToString();
When I try to access the output parameters in the second code, I do not get any values (and I know that they exist in the Sybase database table).
Is there some parameter or order of parameters that I am missing when trying to access Sybase in this fashion?
Thanks.