ado.net 调用带参数的存储过程

    String connString = "Data Source = localhost; Initial Catalog = hkjc;User ID = sa;Pwd = 123";
            SqlConnection conn = new SqlConnection(connString);
            conn.Open();
            SqlCommand cmd = new SqlCommand("GetManagement", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@management", SqlDbType.VarChar, 50).Value = managementname;
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataTable dt=new DataTable();
            sda.Fill(dt);
            cmd.Dispose();
            cmd.Clone();
            conn.Dispose();
            conn.Close();
            return dt;

 

注:GetManagement为存储过程名称  @management为参数名称

你可能感兴趣的:(.net)