public void findflight()
{
// 创建参数
IDataParameter[] parameters = {
new SqlParameter("@Id", SqlDbType.Int,4) ,
new SqlParameter("@Name", SqlDbType.NVarChar) ,
};
// 设置参数类型
parameters[0].Direction = ParameterDirection.Output; // 设置为输出参数
parameters[1].Value = "张三";
LoadDate(“P_FindFlihgt”,parameters);
int id = (int)parameter[0].Value;
}
//调用存储过程返回DateTable
public static DataTable LoadData(string strProcName, params object[] paraValues)
{
DataTable dt = new DataTable();
string strConn = ConfigurationManager.ConnectionStrings["HealthHospInfection"].ConnectionString;
using (SqlConnection conn = new SqlConnection(strConn))
{
try
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strProcName;
// 设置CommandType的类型
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
conn.Open();
if (paraValues != null)
{
//添加参数
cmd.Parameters.AddRange(paraValues);
}
// 取数据
using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
{
adapter.Fill(dt);
}
}
catch (Exception ex)
{
MessageBox.Show("错误:" + ex.Message + "/r/n跟踪:" + ex.StackTrace);
}
finally
{
conn.Close();
}
}
return dt;
}