先使用 sqlDataReader.close() 才能显示正确结果,百思不得其解 ~~~
如果this.Response.Write("new productid= "+comm.Parameters["@id"].Value);
dr.Close();
结果没有 productid
必须 得 dr.Close();
this.Response.Write("new productid= "+comm.Parameters["@id"].Value);
==========================
SqlConnection conn=new SqlConnection("server=localhost;database=northwind;uid=sa;pwd=");
SqlCommand comm= conn.CreateCommand();
conn.Open();
comm.CommandText="exec @id= addP @name ,@supplierId ,@CategoryId ";
comm.Parameters.Add("@id",SqlDbType.Int);
comm.Parameters["@id"].Direction= ParameterDirection.Output;
comm.Parameters.Add("@name","zhao");
comm.Parameters.Add("@supplierid",1);
comm.Parameters.Add("@categoryId",1);
// comm.ExecuteNonQuery();
// this.Response.Write("new productid= "+comm.Parameters["@id"].Value);
SqlDataReader dr= comm.ExecuteReader();
while(dr.Read())
{
this.Response.Write("productname is "+dr["ProductName"]+ "UnitPrice is "+ dr["UnitPrice"]);
}
this.Response.Write("new productid= "+comm.Parameters["@id"].Value);
dr.Close();