public static string GetCustomerCName(ref ArrayList arrayCName,ref ArrayList arrayID)
{
SqlConnection con=ADConnection.createConnection();
SqlCommand cmd=new SqlCommand("testProcedure_AX",con);
cmd.CommandType=CommandType.StoredProcedure;
con.Open();
try
{
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
if(dr[0].ToString()=="")
{
arrayCName.Add(dr[1].ToString());
}
}
con.Close();
return "OK!";
}
catch(Exception ex)
{
con.Close();
return ex.ToString();
}
}
注:其實就是把以前SqlCommand cmd=new SqlCommand("select userID from USERS order by userid desc",con);
中的SQL語句替換為存儲過程名,再把cmd的類型標注為CommandType.StoredProcedure(存儲過程)
CREATE PROCEDURE dbo.AXzhz
/*這里輸注釋*/
@startDate varchar(16),
@endDate varchar(16)
AS
select id from table_AX where commentDateTime>@startDate and commentDateTime<@endDate order by contentownerid DESC
注:@startDate varchar(16)是聲明@startDate 這個變量,多個變量名之間用【,】隔開.后面的SQL就可以使用這個變量了.
我怎麼在ASP.NET中調用這個參數的存儲過程?
public static string GetCustomerCNameCount(string startDate,string endDate,ref DataSet ds)
{
SqlConnection con=ADConnection.createConnection();
//-----------------------注意這一段------------------------------------------
SqlDataAdapter da=new SqlDataAdapter("AXzhz",con);
para0=new SqlParameter("@startDate",startDate);
para1=new SqlParameter("@endDate",endDate);
da.SelectCommand.Parameters.Add(para0);
da.SelectCommand.Parameters.Add(para1);
da.SelectCommand.CommandType=CommandType.StoredProcedure;
//----------------------------------------------------------------------------
try
{
con.Open();
da.Fill(ds);
con.Close();
return "OK";
}
catch(Exception ex)
{
return ex.ToString();
}
}